package com.yc.ship.module.trade.controller.admin.visitor;

import com.yc.ship.framework.common.pojo.CommonResult;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.common.util.collection.CollectionUtils;
import com.yc.ship.framework.common.util.collection.MapUtils;
import com.yc.ship.framework.common.util.object.BeanUtils;
import com.yc.ship.module.product.controller.admin.pricevoyage.vo.PriceVoyageSaveReqVO;
import com.yc.ship.module.trade.controller.admin.insurance.vo.InsuranceRespVO;
import com.yc.ship.module.trade.controller.admin.visitor.vo.VisitorPageReqVO;
import com.yc.ship.module.trade.controller.admin.visitor.vo.VisitorRespVO;
import com.yc.ship.module.trade.dal.dataobject.insurance.InsuranceDO;
import com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO;
import com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO;
import com.yc.ship.module.trade.service.insurance.InsuranceService;
import com.yc.ship.module.trade.service.order.TradeOrderService;
import com.yc.ship.module.trade.service.order.TradeVisitorService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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


import static com.yc.ship.framework.common.pojo.CommonResult.success;

/**
 * 游客信息
 */

@Tag(name = "管理后台 - 订单游客信息")
@RestController
@RequestMapping("/trade/visitor")
@Validated
public class TradeVisitorController {

    @Resource
    private TradeVisitorService tradeVisitorService;


    @GetMapping("/page")
    @Operation(summary = "获得订单游客信息分页")
    @PreAuthorize("@ss.hasPermission('trade:visitor:query')")
    public CommonResult<PageResult<VisitorRespVO>> getInsurancePage(@Valid VisitorPageReqVO pageReqVO) {
        PageResult<VisitorRespVO> pageResult = tradeVisitorService.getVisitorPage(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/get")
    @Operation(summary = "获得订单游客信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('trade:insurance:query')")
    public CommonResult<TradeVisitorDO> getVisitor(@RequestParam("id") Long id) {
        TradeVisitorDO visitor = tradeVisitorService.getVisitor(id);
        return success(visitor);
    }

    @PutMapping("/update")
    @Operation(summary = "更新游客信息")
    @PreAuthorize("@ss.hasPermission('trade:insurance:update')")
    public CommonResult<Boolean> updateVisitor(@Valid @RequestBody TradeVisitorDO updateReqVO) {
        tradeVisitorService.updateVisitor(updateReqVO);
        return success(true);
    }
}
