package com.zsElectric.boot.business.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zsElectric.boot.business.model.dto.AddPolicyFeeDTO;
import com.zsElectric.boot.business.model.dto.UpdateStationTipsDTO;
import com.zsElectric.boot.business.model.query.ThirdPartyStationInfoQuery;
import com.zsElectric.boot.business.model.vo.PartyStationInfoVO;
import com.zsElectric.boot.business.model.vo.ThirdPartyStationInfoVO;
import com.zsElectric.boot.business.model.vo.TimePeriodPriceVO;
import com.zsElectric.boot.business.service.PolicyFeeService;
import com.zsElectric.boot.business.service.ThirdPartyChargingService;
import com.zsElectric.boot.business.service.ThirdPartyInfoService;
import com.zsElectric.boot.core.web.PageResult;
import com.zsElectric.boot.core.web.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 策略费用控制器
 *
 * @author system
 * @since 2025-12-15
 */
@Tag(name = "策略费用管理接口")
@RestController
@RequestMapping("/api/v1/policy-fee")
@RequiredArgsConstructor
public class PolicyFeeController {

    private final PolicyFeeService policyFeeService;

    private final ThirdPartyChargingService chargingService;
    private final ThirdPartyInfoService thirdPartyInfoService;
    /**
     * 获取充电桩信息集合
     *
     */
    @Operation(summary = "获取充电桩信息集合(下拉使用)")
    @GetMapping("/getPartyStationInfo")
    public Result<List<PartyStationInfoVO>> getPartyStationInfo(){
        return Result.success(chargingService.getPartyStationInfo());
    }

    /**
     * 获取渠道方集合
     * */
    @Operation(summary = "获取渠道方集合(下拉使用)")
    @GetMapping("/getPartyStationInfoList")
    public Result<List<PartyStationInfoVO>> getPartyStationInfoList(){
        return Result.success(thirdPartyInfoService.getPartyStationInfoList());
    }

    /**
     * 获取充电站信息分页列表（策略列表）
     *
     * @param queryParams 查询参数
     * @return 充电站信息分页列表
     */
    @Operation(summary = "获取充电站信息分页列表（策略列表）")
    @PostMapping("/getStationInfoPageByEquipment")
    public PageResult<ThirdPartyStationInfoVO> getStationInfoPageByEquipment(@RequestBody ThirdPartyStationInfoQuery queryParams){
        IPage<ThirdPartyStationInfoVO> stationInfoPageByEquipment = chargingService.getStationInfoPageByEquipment(queryParams);
        return PageResult.success(stationInfoPageByEquipment);
    }

    /**
     * 查询策略费用
     *
     * @param stationId 站点信息ID(关联third_party_station_info表)
     * @param salesType 销售类型（0-平台 1-企业 2-渠道方）
     * @param firmId 企业ID（销售类型为1时必填）关联c_firm_info
     * @param thirdPartyId 渠道方ID（销售类型为2时必填）关联c_third_party_info
     * @return 策略费用列表
     */
    @Operation(summary = "查询策略费用")
    @GetMapping("/getPolicyFee")
    public Result<List<TimePeriodPriceVO>> getPolicyFee(
            @Parameter(description = "站点信息ID(关联third_party_station_info表)", required = true)
            @RequestParam Long stationId,
            @Parameter(description = "销售类型（0-平台 1-企业 2-渠道方）", required = true)
            @RequestParam Integer salesType,
            @Parameter(description = "企业ID（销售类型为1时必填）关联c_firm_info")
            @RequestParam(required = false) Long firmId,
            @Parameter(description = "渠道方ID（销售类型为2时必填）关联c_third_party_info")
            @RequestParam(required = false) Long thirdPartyId) {
        return Result.success(policyFeeService.getPolicyFee(stationId, salesType, firmId, thirdPartyId));
    }

    /**
     * 批量新增/修改策略费用
     *
     * @param addPolicyFeeDTOList 策略费用信息列表
     * @return 操作结果
     */
    @Operation(summary = "批量新增/修改策略费用")
    @PostMapping("/addPolicyFee")
    public Result<Boolean> addPolicyFee(@RequestBody List<AddPolicyFeeDTO> addPolicyFeeDTOList) {
        return Result.success(policyFeeService.batchAddPolicyFee(addPolicyFeeDTOList));
    }

    /**
     * 修改站点提示语
     *
     * @param dto 修改站点提示语入参
     * @return 操作结果
     */
    @Operation(summary = "修改站点提示语")
    @PostMapping("/updateStationTips")
    public Result<Boolean> updateStationTips(@RequestBody UpdateStationTipsDTO dto) {
        return Result.success(chargingService.updateStationTips(dto.getStationId(), dto.getStationTips()));
    }
}
