package com.dora.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.PositiveOrZero;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 管理端积分套餐相关DTO
 * 
 * @author 1818AI
 * @since 2025-10-24
 */
public class AdminPointsPackageDto {
    
    // 私有构造函数，防止实例化
    private AdminPointsPackageDto() {
    }

    /**
     * 创建/更新套餐请求
     */
    @Data
    @Schema(description = "管理端创建/更新积分套餐请求")
    public static class CreateOrUpdatePackageRequest {
        @NotBlank(message = "套餐名称不能为空")
        @Schema(description = "套餐名称", example = "超值包")
        private String name;

        @Schema(description = "套餐描述", example = "性价比之选，适合日常使用")
        private String description;

        @NotNull(message = "基础积分不能为空")
        @Positive(message = "基础积分必须大于0")
        @Schema(description = "基础积分数量", example = "1000")
        private Integer points;

        @PositiveOrZero(message = "赠送积分不能为负数")
        @Schema(description = "赠送积分数量", example = "150")
        private Integer bonusPoints = 0;

        @NotNull(message = "价格不能为空")
        @Positive(message = "价格必须大于0")
        @Schema(description = "套餐价格（元）", example = "88.00")
        private BigDecimal price;

        @Schema(description = "原价（用于显示优惠）", example = "100.00")
        private BigDecimal originalPrice;

        @Positive(message = "积分有效期必须大于0")
        @Schema(description = "积分有效期（天）", example = "365")
        private Integer pointsExpireDays = 365;

        @Schema(description = "优惠标签", example = "赠送150积分")
        private String discountLabel;

        @Schema(description = "排序值（数字越小越靠前）", example = "1")
        private Integer sortOrder = 0;

        @Schema(description = "是否热门推荐（0-否，1-是）", example = "1")
        private Integer isHot = 0;

        @Schema(description = "是否上架（0-下架，1-上架）", example = "1")
        private Integer isActive = 1;
    }

    /**
     * 管理端套餐响应（包含更多统计信息）
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "管理端积分套餐信息响应")
    public static class AdminPackageResponse {
        @Schema(description = "套餐ID", example = "1")
        private Long id;

        @Schema(description = "套餐名称", example = "超值包")
        private String name;

        @Schema(description = "套餐描述", example = "性价比之选")
        private String description;

        @Schema(description = "基础积分", example = "1000")
        private Integer points;

        @Schema(description = "赠送积分", example = "150")
        private Integer bonusPoints;

        @Schema(description = "总积分", example = "1150")
        private Integer totalPoints;

        @Schema(description = "价格", example = "88.00")
        private BigDecimal price;

        @Schema(description = "原价", example = "100.00")
        private BigDecimal originalPrice;

        @Schema(description = "积分有效期（天）", example = "365")
        private Integer pointsExpireDays;

        @Schema(description = "优惠标签", example = "赠送150积分")
        private String discountLabel;

        @Schema(description = "排序值", example = "1")
        private Integer sortOrder;

        @Schema(description = "是否热门推荐", example = "true")
        private Boolean isHot;

        @Schema(description = "是否上架", example = "true")
        private Boolean isActive;

        @Schema(description = "创建时间")
        private LocalDateTime createTime;

        @Schema(description = "更新时间")
        private LocalDateTime updateTime;

        // 管理端特有的统计信息
        @Schema(description = "购买次数", example = "156")
        private Long purchaseCount;

        @Schema(description = "总销售额", example = "13728.00")
        private BigDecimal totalSales;

        @Schema(description = "最后购买时间")
        private LocalDateTime lastPurchaseTime;
    }

    /**
     * 批量排序请求
     */
    @Data
    @Schema(description = "批量更新套餐排序请求")
    public static class BatchSortRequest {
        @NotNull(message = "套餐ID列表不能为空")
        @Schema(description = "套餐ID列表，按照期望的排序顺序排列", example = "[1, 3, 2, 4]")
        private List<Long> packageIds;
    }

    /**
     * 批量状态更新请求
     */
    @Data
    @Schema(description = "批量更新套餐状态请求")
    public static class BatchStatusRequest {
        @NotNull(message = "套餐ID列表不能为空")
        @Schema(description = "套餐ID列表", example = "[1, 2, 3]")
        private List<Long> packageIds;

        @NotNull(message = "状态值不能为空")
        @Schema(description = "是否上架（0-下架，1-上架）", example = "1")
        private Integer isActive;
    }

    /**
     * 套餐销售统计响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "套餐销售统计信息")
    public static class PackageSalesStatsResponse {
        @Schema(description = "套餐ID", example = "1")
        private Long packageId;

        @Schema(description = "套餐名称", example = "超值包")
        private String packageName;

        @Schema(description = "销售数量", example = "156")
        private Long salesCount;

        @Schema(description = "销售金额", example = "13728.00")
        private BigDecimal salesAmount;

        @Schema(description = "销售积分总数", example = "179400")
        private Long totalPoints;

        @Schema(description = "平均客单价", example = "88.00")
        private BigDecimal avgOrderValue;

        @Schema(description = "最后销售时间")
        private LocalDateTime lastSaleTime;

        @Schema(description = "销售占比", example = "23.5")
        private Double salesRatio;
    }

    /**
     * 套餐概览统计响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "套餐概览统计")
    public static class PackageOverviewStatsResponse {
        @Schema(description = "总套餐数", example = "6")
        private Long totalPackages;

        @Schema(description = "上架套餐数", example = "5")
        private Long activePackages;

        @Schema(description = "下架套餐数", example = "1")
        private Long inactivePackages;

        @Schema(description = "热门套餐数", example = "3")
        private Long hotPackages;

        @Schema(description = "总销售额", example = "58640.00")
        private BigDecimal totalSales;

        @Schema(description = "总销售次数", example = "663")
        private Long totalSalesCount;

        @Schema(description = "平均客单价", example = "88.46")
        private BigDecimal avgOrderValue;

        @Schema(description = "最畅销套餐ID", example = "2")
        private Long bestSellingPackageId;

        @Schema(description = "最畅销套餐名称", example = "标准包")
        private String bestSellingPackageName;

        @Schema(description = "统计时间范围开始")
        private LocalDateTime statsStartTime;

        @Schema(description = "统计时间范围结束")
        private LocalDateTime statsEndTime;
    }

    /**
     * 套餐查询条件
     */
    @Data
    @Schema(description = "套餐查询条件")
    public static class PackageQueryRequest {
        @Schema(description = "套餐名称（模糊查询）", example = "标准")
        private String name;

        @Schema(description = "是否上架（null-全部，0-下架，1-上架）", example = "1")
        private Integer isActive;

        @Schema(description = "是否热门（null-全部，0-否，1-是）", example = "1")
        private Integer isHot;

        @Schema(description = "最低价格", example = "10.00")
        private BigDecimal minPrice;

        @Schema(description = "最高价格", example = "1000.00")
        private BigDecimal maxPrice;

        @Schema(description = "排序字段（price-价格，points-积分，createTime-创建时间，salesCount-销量）", example = "createTime")
        private String sortField = "createTime";

        @Schema(description = "排序方向（asc-升序，desc-降序）", example = "desc")
        private String sortDirection = "desc";

        @Schema(description = "页码", example = "1")
        private Integer page = 1;

        @Schema(description = "每页数量", example = "10")
        private Integer size = 10;
    }
}
