using ERPCore.Common.Http;
using ERPCore.Domain.Enums;
using ERPCore.Dtos.Common;
using ERPCore.Dtos.Production;

namespace ERPCore.Services.Interfaces;

/// <summary>
/// Production template CRUD and graph validation (docs/30 §D.1, FR-MFG-01..07).
/// </summary>
public interface IProductionTemplateService
{
    Task<PagedResponse<TemplateSummaryDto>> ListAsync(PageQuery query, EntityStatus? status, CancellationToken ct = default);

    Task<ETagged<TemplateGraphDto>?> GetAsync(int templateId, CancellationToken ct = default);

    Task<ETagged<TemplateGraphDto>> CreateAsync(SaveTemplateRequest request, CancellationToken ct = default);

    /// <summary>
    /// Replaces the whole graph. Requires the current row version (<c>If-Match</c>) and is
    /// refused with <c>409 TEMPLATE_IN_USE</c> while any run of this template is
    /// InProgress — edit-lock stands in for versioning (FR-MFG-06).
    /// </summary>
    Task<ETagged<TemplateGraphDto>> UpdateAsync(
        int templateId, SaveTemplateRequest request, uint expectedRowVersion, CancellationToken ct = default);

    /// <summary>
    /// Activate/deactivate (FR-MFG-01). Deliberately <b>not</b> edit-locked: deactivating is
    /// the "never delete a referenced master" path (FR-MD-08) and only stops <i>new</i> runs
    /// being started, so it must stay available while runs are in flight.
    /// </summary>
    Task SetStatusAsync(int templateId, EntityStatus status, CancellationToken ct = default);
}
