using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json.Linq;

namespace SicboSub.Web.Models
{
    #region Auth Request/Response

    /// <summary>
    /// Request đăng nhập bằng token từ URL
    /// </summary>
    public class TokenLoginReq
    {
        [Required]
        public string? token { get; set; }

        public string? language { get; set; }
    }

    /// <summary>
    /// Data trả về sau khi login thành công
    /// </summary>
    public class TokenLoginData
    {
        public decimal id { get; set; }
        public string? msisdn { get; set; }
        public string? username { get; set; }
        public string? fullname { get; set; }
        public string? picture { get; set; }
        public decimal winCoin { get; set; }
        public decimal betCoin { get; set; }
        public int? point { get; set; }
        public int? freeSpin { get; set; }
        public byte? status { get; set; }
        public bool isRegistered { get; set; }
        public RegInfoData? regPkg { get; set; }
    }

    public class RegInfoData
    {
        public decimal RegisterId { get; set; }
        public string? Msisdn { get; set; }
        public string? ProductName { get; set; }
        public DateTime? RegisterTime { get; set; }
        public short? NumberSpin { get; set; }
        public byte? Status { get; set; } // Matches API byte/byte?
        public DateTime? ExpireTime { get; set; }
        public byte? Renew { get; set; }
    }

    /// <summary>
    /// Response login - kế thừa CommonResponse
    /// </summary>
    public class TokenLoginRes : CommonResponse
    {
        public TokenLoginData? data { get; set; }

        public TokenLoginRes(string dataGet)
        {
            JObject jObject = JObject.Parse(dataGet);
            BuildCommonResponse(dataGet);

            if (jObject != null && jObject["data"] != null)
            {
                data = jObject["data"]!.ToObject<TokenLoginData>();
            }
        }
    }

    /// <summary>
    /// Request lấy thông tin tài khoản
    /// </summary>
    public class AccountInfoReq
    {
        public string msisdn { get; set; } = null!;
        public string? lang { get; set; }
    }

    /// <summary>
    /// Response lấy thông tin tài khoản
    /// </summary>
    public class AccountInfoRes : CommonResponse
    {
        public TokenLoginData? data { get; set; } // Re-use TokenLoginData as it has same structure

        public AccountInfoRes(string dataGet)
        {
            JObject jObject = JObject.Parse(dataGet);
            BuildCommonResponse(dataGet);

            if (jObject != null && jObject["data"] != null)
            {
                data = jObject["data"]!.ToObject<TokenLoginData>();
            }
        }
    }

    #endregion
}
