using System.ComponentModel.DataAnnotations;
using Tiku.Application.Commerce;

namespace Tiku.Api.Contracts;

public sealed class CreateCommerceOrderDto
{
    [Required]
    public Guid PlanId { get; set; }

    [Range(1, 99)]
    public int Quantity { get; set; } = 1;

    [StringLength(50)]
    public string? PayMethod { get; set; }

    [StringLength(50)]
    public string? PayProvider { get; set; }

    public Guid? RegionId { get; set; }

    [StringLength(100)]
    public string? CouponCode { get; set; }

    public Guid? CouponRedemptionId { get; set; }

    public CreateCommerceOrderCommand ToCommand()
    {
        return new CreateCommerceOrderCommand(
            PlanId,
            Quantity,
            PayMethod,
            PayProvider,
            RegionId,
            CouponCode,
            CouponRedemptionId);
    }
}

public sealed class CommerceOrderQueryDto
{
    [Range(1, 100)]
    public int? Limit { get; set; }

    [StringLength(32)]
    public string? Status { get; set; }
}

public sealed class CreateCommercePaymentDto
{
    [Required]
    [StringLength(100)]
    public string OrderNo { get; set; } = string.Empty;

    [Required]
    [StringLength(50)]
    public string Provider { get; set; } = string.Empty;

    [Required]
    [StringLength(50)]
    public string Method { get; set; } = string.Empty;

    [StringLength(255)]
    public string? OpenId { get; set; }

    [StringLength(2048)]
    public string? ReturnUrl { get; set; }

    [StringLength(2048)]
    public string? QuitUrl { get; set; }

    public CreateCommercePaymentCommand ToCommand()
    {
        return new CreateCommercePaymentCommand(
            OrderNo,
            Provider,
            Method,
            OpenId,
            ReturnUrl,
            QuitUrl);
    }
}

public sealed class CommerceCouponQueryDto
{
    [Range(1, 100)]
    public int? Limit { get; set; }

    [StringLength(32)]
    public string? Status { get; set; }

    public CommerceCouponQuery ToQuery()
    {
        return new CommerceCouponQuery(Limit, Status);
    }
}

public sealed class ClaimCommerceCouponDto
{
    [Required]
    [StringLength(100)]
    public string CouponCode { get; set; } = string.Empty;

    public ClaimCommerceCouponCommand ToCommand()
    {
        return new ClaimCommerceCouponCommand(CouponCode);
    }
}

public sealed class CheckCommerceCouponDto
{
    [StringLength(100)]
    public string? CouponCode { get; set; }

    public Guid? CouponRedemptionId { get; set; }

    [Required]
    public Guid PlanId { get; set; }

    [Range(1, 99)]
    public int Quantity { get; set; } = 1;

    public Guid? RegionId { get; set; }

    public CheckCommerceCouponCommand ToCommand()
    {
        return new CheckCommerceCouponCommand(CouponCode, CouponRedemptionId, PlanId, Quantity, RegionId);
    }
}
