package com.backendsys.modules.cms.siteinfo.controller;

import com.backendsys.modules.cms.siteinfo.entity.SiteInfo;
import com.backendsys.modules.cms.siteinfo.service.SiteInfoService;
import com.backendsys.modules.common.config.security.annotations.Anonymous;
import com.backendsys.modules.common.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Validated
@RestController
@Tag(name = "站点管理")
public class SiteInfoController {

    @Autowired
    private SiteInfoService siteInfoService;

    @Operation(summary = "获取站点信息")
    @PreAuthorize("@sr.hasPermission('10.5')")
    @GetMapping("/api/cms/site/getSiteInfo")
    public Result getSiteInfo() {
        return Result.success().put("data", siteInfoService.selectSiteInfo());
    }

    @Operation(summary = "编辑站点信息")
    @PreAuthorize("@sr.hasPermission('10.5.1')")
    @PutMapping("/api/cms/site/updateSiteInfo")
    public Result updateSiteInfo(@Validated(SiteInfo.Update.class) @RequestBody SiteInfo siteInfo) {
        siteInfo.setId(1L);
        return Result.success().put("data", siteInfoService.updateSiteInfo(siteInfo));
    }

    @Anonymous
    @Operation(summary = "获取站点信息 (公开)")
    @GetMapping("/api/app/cms/site/getSiteInfo")
    public Result getSiteInfoPublic() {
        return Result.success().put("data", siteInfoService.selectSiteInfo());
    }

}
