package com.seer.teach.iot.admin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.seer.teach.iot.admin.req.SaveAdvertisementReq;
import com.seer.teach.iot.admin.service.AdminAdvertisementService;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.LogPrint;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.util.List;

/**
 * 广告页面控制器类
 * <p>
 * 该控制器用于处理广告页面相关的系统信息请求，提供系统信息的获取功能。
 *
 */
@RequestMapping("/iot/advertisement")
@RestController
@Tag(name = "广告页管理")
@Validated
@RequiredArgsConstructor
@SaCheckLogin
public class AdvertisementPageController {

    private final AdminAdvertisementService adminAdvertisementService;

    @GetMapping("/list")
    @LogPrint
    @Operation(summary = "图片List")
    public ResultBean<List<String>> list() {
        List<String> results = adminAdvertisementService.list();
        return ResultBean.success(results);
    }

    @PostMapping("/upload")
    @LogPrint
    @Operation(summary = "上传广告图片")
    public ResultBean<String> upload(@RequestBody @Validated @NotNull(message = "文件不可为空") MultipartFile file) {
        String result = adminAdvertisementService.upload(file);
        return ResultBean.success(result);
    }

    @PostMapping("/save")
    @LogPrint
    @Operation(summary = "保存广告图片")
    public ResultBean save(@RequestBody
                           @NotEmpty(message = "广告图片列表不能为空")
                           @Size(max = 8, message = "广告图片数量不能超过8个") List<@Valid SaveAdvertisementReq> params) {
        adminAdvertisementService.save(params);
        return ResultBean.success();
    }

}
