using System.ComponentModel.DataAnnotations;
namespace ROLAC.API.DTOs.Disbursement;

// ── Approved-unpaid expenses, grouped by payee (the issue-check worklist) ──────

public class ExpenseLineDto
{
    public int     ExpenseId    { get; set; }
    public string  ExpenseDate  { get; set; } = "";   // yyyy-MM-dd
    public string  Description  { get; set; } = "";
    public decimal Amount       { get; set; }
    public string  MinistryName { get; set; } = "";
    public string  CategoryName { get; set; } = "";
}

public class PayeeGroupDto
{
    public string  PayeeType  { get; set; } = "Vendor"; // Vendor | Member
    public int?    MemberId   { get; set; }
    public string? VendorKey  { get; set; }             // normalized vendor name (grouping key)
    public string  PayeeName  { get; set; } = "";
    public string? Address    { get; set; }
    public string? City       { get; set; }
    public string? State      { get; set; }
    public string? Zip        { get; set; }
    public decimal TotalAmount { get; set; }
    public List<ExpenseLineDto> Lines { get; set; } = [];
}

// ── Issue checks ──────────────────────────────────────────────────────────────

public class PayeeCheckInstruction
{
    [Required] public string PayeeType { get; set; } = "Vendor";
    public int?    MemberId  { get; set; }
    public string? VendorKey { get; set; }
    [Required, MaxLength(200)] public string PayeeName { get; set; } = "";
    [MaxLength(500)] public string? Address { get; set; }
    [MaxLength(100)] public string? City    { get; set; }
    [MaxLength(50)]  public string? State   { get; set; }
    [MaxLength(20)]  public string? Zip     { get; set; }
    [MaxLength(50)]  public string? CheckNumberOverride { get; set; }
    [MaxLength(500)] public string? Memo    { get; set; }
    [Required, MinLength(1)] public List<int> ExpenseIds { get; set; } = [];
}

public class IssueChecksRequest
{
    [Required] public DateOnly CheckDate { get; set; }
    [Required, MinLength(1)] public List<PayeeCheckInstruction> Payees { get; set; } = [];
}

public class IssuedCheckDto
{
    public int     CheckId     { get; set; }
    public string  CheckNumber { get; set; } = "";
    public string  PayeeName   { get; set; } = "";
    public decimal Amount      { get; set; }
}

public class IssueChecksResultDto
{
    public List<IssuedCheckDto> Created { get; set; } = [];
}

// ── Check register / detail ───────────────────────────────────────────────────

public class CheckListItemDto
{
    public int     Id          { get; set; }
    public string  CheckNumber { get; set; } = "";
    public string  CheckDate   { get; set; } = "";   // yyyy-MM-dd
    public decimal Amount      { get; set; }
    public string  PayeeType   { get; set; } = "";
    public string  PayeeName   { get; set; } = "";
    public string  Status      { get; set; } = "";
    public int     LineCount   { get; set; }
    public bool    Signed      { get; set; }
    public string? ReceiptSignedName { get; set; }
    public DateTimeOffset? ReceiptSignedAt { get; set; }
}

public class CheckLineDto
{
    public int     ExpenseId   { get; set; }
    public string  Description { get; set; } = "";
    public decimal Amount      { get; set; }
}

public class CheckDetailDto : CheckListItemDto
{
    public int?    MemberId    { get; set; }
    public string? Address     { get; set; }
    public string? City        { get; set; }
    public string? State       { get; set; }
    public string? Zip         { get; set; }
    public string? Memo        { get; set; }
    public string? VoidReason  { get; set; }
    public DateTimeOffset? VoidedAt { get; set; }
    public DateTimeOffset  IssuedAt { get; set; }
    public List<CheckLineDto> Lines { get; set; } = [];
}

public class VoidCheckRequest
{
    [MaxLength(500)] public string? Reason { get; set; }
}
