package org.jeecg.modules.okki.site.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHeaders;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.okki.site.service.IOkkiSiteService;
import org.jeecg.modules.okki.site.entity.OkkiSite;
import org.jeecg.modules.okki.site.param.ChangeSiteStatusParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * @Description: 站点
 * @Author: Jack
 * @Date:   2024-04-29
 * @Version: V1.0
 */
@RestController
@Slf4j
@RequestMapping("/website")
public class ShopApiController {

    @Autowired
    private IOkkiSiteService okkiSiteService;

    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody OkkiSite okkiSite, @RequestHeader(HttpHeaders.AUTHORIZATION) String authorization) {
        log.info("请求参数 param" + okkiSite.toString() + "authorization" + authorization);
        String Authorization = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImRlYW4iLCJleHAiOjE3MTQ0NjU5Njl9.QdCBYR8mioXcKGi1n5RdMQ5RbJHCSGbE8dkdwYuOXh4";
        if (!authorization.equals(Authorization)) {
            return Result.error("sign 验证不通过");
        }
        // 如果站点id已存在 则提示信息
        boolean result = okkiSiteService.insertSite(okkiSite);
        log.info("请求成功，返回结果" + result);
        if (result) {
            return Result.OK("添加成功！");
        }else {
            return Result.error("添加失败！");
        }
    }

    @PostMapping(value = "/edit")
    public Result<String> edit(@RequestBody OkkiSite okkiSite, @RequestHeader(HttpHeaders.AUTHORIZATION) String authorization) {
        log.info("请求参数 param" + okkiSite.toString() + "authorization" + authorization);
        String Authorization = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImRlYW4iLCJleHAiOjE3MTQ0NjU5Njl9.QdCBYR8mioXcKGi1n5RdMQ5RbJHCSGbE8dkdwYuOXh4";
        if (!authorization.equals(Authorization)) {
            return Result.error("sign 验证不通过");
        }
        boolean result = okkiSiteService.updateBySiteId(okkiSite);
        log.info("请求成功，返回结果" + result);
        if (result) {
            return Result.OK("编辑成功！");
        }else {
            return Result.error("编辑失败！");
        }
    }

    @PostMapping(value = "/changeStatus")
    public Result<String> changeStatus(@RequestBody ChangeSiteStatusParam param, @RequestHeader(HttpHeaders.AUTHORIZATION) String authorization) {
        log.info("请求参数 param" + param.toString() + ",authorization" + authorization);
        String Authorization = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImRlYW4iLCJleHAiOjE3MTQ0NjU5Njl9.QdCBYR8mioXcKGi1n5RdMQ5RbJHCSGbE8dkdwYuOXh4";
        if (!authorization.equals(Authorization)) {
            return Result.error("sign 验证不通过");
        }
        boolean result = okkiSiteService.okkiChangeStatus(param);
        log.info("请求成功，返回结果" + result);
        if (result == true) {
            return Result.OK("编辑成功！");
        }else {
            return Result.error("编辑失败！");
        }
    }
}
