using System.Text.Json.Serialization;

namespace Elfisa.Core;

public sealed class LoginRequest
{
    [JsonPropertyName("username")] public string Username { get; set; } = "";
    [JsonPropertyName("password")] public string Password { get; set; } = "";
}

public sealed class LoginResponse
{
    [JsonPropertyName("token")] public string? Token { get; set; }
    [JsonPropertyName("role")] public string? Role { get; set; }
    [JsonPropertyName("redirect_url")] public string? RedirectUrl { get; set; }
}

public sealed class BuyerReportResponse
{
    [JsonPropertyName("lines")] public List<BuyerReportLineDto>? Lines { get; set; }
}

public sealed class BuyerReportLineDto
{
    [JsonPropertyName("order_id")] public string? OrderId { get; set; }
    [JsonPropertyName("global_sign")] public string? GlobalSign { get; set; }
    [JsonPropertyName("order_date")] public DateTime? OrderDate { get; set; }
    [JsonPropertyName("status")] public string? Status { get; set; }
    [JsonPropertyName("supplier")] public string? Supplier { get; set; }
    [JsonPropertyName("location")] public string? Location { get; set; }
    [JsonPropertyName("item_name")] public string? ItemName { get; set; }
    [JsonPropertyName("item_code")] public string? ItemCode { get; set; }
    [JsonPropertyName("qty")] public decimal Qty { get; set; }
    [JsonPropertyName("unit_price")] public decimal UnitPrice { get; set; }
    [JsonPropertyName("sum")] public decimal Sum { get; set; }
}

public sealed class AiReportRequest
{
    [JsonPropertyName("prompt")] public string Prompt { get; set; } = "";
    [JsonPropertyName("token")] public string Token { get; set; } = "";
    [JsonPropertyName("format")] public string Format { get; set; } = "docx";
}

public sealed class AiReportResult
{
    public byte[] Content { get; set; } = Array.Empty<byte>();
    public string FileName { get; set; } = "report.docx";
}

public sealed class ErrorResponse
{
    [JsonPropertyName("error")] public string? Error { get; set; }
}

public sealed class PriceSummaryResponse
{
    [JsonPropertyName("summary")] public List<PriceItem>? Summary { get; set; }
    [JsonPropertyName("total_drugs")] public int TotalDrugs { get; set; }
}

public sealed class PriceItem
{
    [JsonPropertyName("supplier_price_id")] public string? SupplierPriceId { get; set; }
    [JsonPropertyName("supplier_name")] public string? SupplierName { get; set; }
    [JsonPropertyName("drug_name")] public string? DrugName { get; set; }
    [JsonPropertyName("cure_form")] public string? CureForm { get; set; }
    [JsonPropertyName("barcode")] public string? Barcode { get; set; }
    [JsonPropertyName("price")] public decimal Price { get; set; }
    [JsonPropertyName("quantity")] public decimal Quantity { get; set; }
    [JsonPropertyName("manufacturer")] public string? Manufacturer { get; set; }
    [JsonPropertyName("trade_name")] public string? TradeName { get; set; }
    [JsonPropertyName("es_code")] public long EsCode { get; set; }
}

public sealed class BuyerLocationDto
{
    [JsonPropertyName("buyer_location_id")] public string? BuyerLocationId { get; set; }
    [JsonPropertyName("address")] public string? Address { get; set; }
    [JsonPropertyName("region_name")] public string? RegionName { get; set; }
    [JsonPropertyName("is_default")] public bool IsDefault { get; set; }
    public override string ToString() => Address ?? "";
}

public sealed class BuyerOrderItemReq
{
    [JsonPropertyName("supplier_price_id")] public string SupplierPriceId { get; set; } = "";
    [JsonPropertyName("qty")] public double Qty { get; set; }
    [JsonPropertyName("item_name")] public string? ItemName { get; set; }
    [JsonPropertyName("barcode")] public string? Barcode { get; set; }
}

public sealed class BuyerOrderCreateRequest
{
    [JsonPropertyName("location_id")] public string? LocationId { get; set; }
    [JsonPropertyName("comment")] public string? Comment { get; set; }
    [JsonPropertyName("global_sign")] public string? GlobalSign { get; set; }
    [JsonPropertyName("items")] public List<BuyerOrderItemReq> Items { get; set; } = new();
}

public sealed class BuyerOrderResponse
{
    [JsonPropertyName("order_id")] public string? OrderId { get; set; }
    [JsonPropertyName("status")] public string? Status { get; set; }
    [JsonPropertyName("global_sign")] public string? GlobalSign { get; set; }
    [JsonPropertyName("total_amount")] public decimal TotalAmount { get; set; }
    [JsonPropertyName("items_count")] public int ItemsCount { get; set; }
}
