package com.ruoyi.dashboard.domain.revenueStat;

import com.ruoyi.bst.device.domain.DeviceQuery;
import com.ruoyi.bst.lightingNum.domain.LightingNum;
import com.ruoyi.bst.lightingNum.domain.LightingNumQuery;
import com.ruoyi.bst.order.domain.OrderQuery;
import com.ruoyi.bst.order.domain.enums.OrderStatus;
import com.ruoyi.bst.order.domain.query.OrderRefundQuery;
import com.ruoyi.bst.refund.domain.RefundQuery;
import com.ruoyi.bst.refund.domain.enums.RefundStatus;
import com.ruoyi.bst.store.domain.StoreQuery;
import com.ruoyi.system.user.domain.UserQuery;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.util.List;

@Data
public class RevenueStatQuery {
    @ApiModelProperty("日期范围")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private List<LocalDate> dateRange;

    @ApiModelProperty("查询数据")
    private List<String> keys;

    @ApiModelProperty("用户ID")
    private Long userId;

    @ApiModelProperty("商户ID")
    private Long mchId;

    @ApiModelProperty("店铺ID")
    private Long storeId;

    @ApiModelProperty("数据隔离")
    private Boolean scope;

    // 基础订单查询
    private OrderQuery baseOrderQuery() {
        OrderQuery query = new OrderQuery();
        query.setStatusList(OrderStatus.payed());
        query.setStoreId(storeId);
        query.setScope(scope);
        return query;
    }

    // 订单查询
    public OrderQuery toOrderQuery() {
        OrderQuery query = baseOrderQuery();
        query.setCreateDateRange(dateRange);
        query.setMchId(mchId);
        return query;
    }


    // 用户订单查询
    public OrderQuery toUserOrderQuery() {
        OrderQuery query = baseOrderQuery();
        query.setCreateDateRange(dateRange);
        query.setUserId(userId);
        return query;
    }

    // 用户退款查询（完成订单）
    public OrderQuery toOrderQueryForEnd() {
        OrderQuery query = baseOrderQuery();
        query.setEndDateRange(dateRange);
        query.setMchId(mchId);
        query.setStatusList(OrderStatus.payed());
        return query;
    }

    // 用户订单退款查询
    public OrderRefundQuery toUserOrderRefundQuery() {
        OrderRefundQuery query = new OrderRefundQuery();
        // query.setStatusList(OrderStatus.valid());
        //query.setStatus(RefundStatus.valid());
        query.setRefundCreateDateRange(dateRange);
        query.setStoreId(storeId);
        query.setUserId(userId);
        query.setScope(scope);
        return query;
    }

    // 店铺查询
    public StoreQuery toStoreQuery() {
        StoreQuery query = new StoreQuery();
        query.setCreateDateRange(dateRange);
        query.setUserId(mchId);
        query.setScope(scope);
        return query;
    }

    // 设备查询
    public DeviceQuery toDeviceQuery() {
        DeviceQuery query = new DeviceQuery();
        query.setCreateDateRange(dateRange);
        query.setStoreId(storeId);
        query.setUserId(mchId);
        query.setScope(scope);
        return query;
    }

    // 爆灯次数查询
    public LightingNumQuery toLightingNumQuery() {
        LightingNumQuery query = new LightingNumQuery();
        query.setStoreId(storeId);
        query.setUserId(userId);
        query.setScope(scope);
        return query;
    }

    // 订单退款查询
    public OrderRefundQuery toOrderRefundQuery() {
        OrderRefundQuery query = new OrderRefundQuery();
       // query.setStatusList(OrderStatus.valid());
        //query.setStatus(RefundStatus.valid());
        query.setRefundCreateDateRange(dateRange);
        query.setStoreId(storeId);
        query.setMchId(mchId);
        query.setScope(scope);
        return query;
    }

    // 用户查询
    public UserQuery toUserQuery() {
        UserQuery query = new UserQuery();
        query.setCreateDateRange(dateRange);
        query.setUserId(mchId);
        query.setScope(scope);
        return query;
    }

}
