package com.ylx.fareSetting.controller;

import com.ylx.common.core.domain.R;
import com.ylx.fareSetting.domian.dto.FareCalculateDTO;
import com.ylx.fareSetting.domian.vo.FareCalculateResultVO;
import com.ylx.fareSetting.service.IMaProjectFareSettingService;
import com.ylx.massage.domain.dto.DriverFeeDTO;
import com.ylx.massage.domain.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/project/fare/setting")
@Api(tags = {"项目车费标准设置"})
@Slf4j
public class MaProjectFareSettingController {

    @Resource
    private IMaProjectFareSettingService maProjectFareSettingService;

    @PreAuthorize("@customerAuth.isCustomer()")
    @PostMapping("/calculate")
    @ApiOperation("下单前计算打车费")
    public R<FareCalculateResultVO> calculate(@Validated @RequestBody FareCalculateDTO dto) {
        FareCalculateResultVO result = maProjectFareSettingService.calculateFare(dto);
        return R.ok(result);
    }


    /**
     * 保存免车费设置
     */
    @PostMapping("/save")
    @ApiOperation("保存免车费设置")
    public R<String> save(@RequestBody @Valid DriverFeeDTO dto) {
        maProjectFareSettingService.saveOrUpdateFee(dto);
        return R.ok("设置成功");
    }
}
