package com.cool.store.controller.webc;

import com.cool.store.context.PartnerUserHolder;
import com.cool.store.dto.FoodTokenDTO;
import com.cool.store.dto.GetAccessTokenDTO;
import com.cool.store.dto.ModifyPasswordDTO;
import com.cool.store.dto.ShopAccount.ShopAccountDTO;
import com.cool.store.request.GetPasswordDTO;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author suzhuhong
 * @Date 2025/4/8 16:17
 * @Version 1.0
 */
@RestController
@Api(tags ="小程序账号管理")
@RequestMapping({"/mini/account"})
public class MiniShopAccountController {


    @Resource
    ShopAccountService accountService;

    @Resource
    PushService pushService;

    @Resource
    ThirdXinGuanJiaService thirdXinGuanJiaService;

    @Resource
    ThirdFoodService thirdFoodService;
    @Resource
    EnterpriseService enterpriseService;


    @ApiOperation("根据门店shopId查询平台账号")
    @GetMapping("/getShopAccountByShopId")
    public ResponseResult<List<ShopAccountDTO>> getShopAccountByShopId(@RequestParam(value = "shopId", required = true) Long shopId) {
        return ResponseResult.success(accountService.getShopAccountByShopId(shopId));
    }


    @ApiOperation("修改密码")
    @PostMapping("/modifyPassword")
    public ResponseResult<Boolean> modifyPassword(@RequestBody ModifyPasswordDTO request) {
        return ResponseResult.success(accountService.modifyPassword(request));
    }

    @ApiOperation("获取云流水免登token")
    @PostMapping("/getYlsToken")
    public ResponseResult<String> getYlsToken(@RequestBody @Validated GetAccessTokenDTO dto) {
        return ResponseResult.success(pushService.getYlsToken(dto));
    }

    @ApiOperation("获取POS免登token")
    @PostMapping("/getPosToken")
    public ResponseResult<String> getPosToken(@RequestBody @Validated GetAccessTokenDTO dto) {
        return ResponseResult.success(pushService.getPosToken(dto));
    }

    @ApiOperation("获取新掌柜免登token")
    @PostMapping("/getXzgToken")
    public ResponseResult<String> getXzgToken(@RequestBody @Validated GetAccessTokenDTO dto) {
        return ResponseResult.success(pushService.getXzgToken(dto));
    }

    @ApiOperation("获取菜品市场token")
    @PostMapping("/getFoodToken")
    public ResponseResult<String> getFoodToken(@RequestBody @Validated FoodTokenDTO dto) {
        return ResponseResult.success(thirdFoodService.getFoodToken(dto));
    }

    @ApiOperation("获取加密子串")
    @PostMapping("/getEncryptedSubstring")
    public ResponseResult<String> getEncryptedSubstring(@RequestBody GetPasswordDTO dto) {
        return ResponseResult.success(thirdXinGuanJiaService.getPassword(dto));
    }

    @ApiOperation("门店编码换云流水编码")
    @GetMapping("/shopCodeToYlsCode")
    public ResponseResult<String> shopCodeToYlsCode(@RequestParam(value = "shopId",required = true) Long shopId) {
        return ResponseResult.success(accountService.shopIdToYlsCode(shopId));
    }

    @ApiOperation("获取标品登录token")
    @GetMapping("/getAccessToken")
    public ResponseResult<String> getAccessToken() {
        return ResponseResult.success(enterpriseService.getLoginInfo(PartnerUserHolder.getUser().getMobile()).getAccessToken());
    }

}
