package com.gxwebsoft.common.system.controller;

import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.system.entity.TenantPackage;
import com.gxwebsoft.common.system.service.TenantPackageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

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

/**
 * 租户套餐控制器
 *
 * @author WebSoft
 * @since 2025-12-12
 */
@Tag(name = "租户套餐管理")
@RestController
@RequestMapping("/api/system/package")
public class TenantPackageController extends BaseController {

    @Resource
    private TenantPackageService tenantPackageService;

    @Operation(summary = "查询所有上架套餐")
    @GetMapping("/list")
    public ApiResult<List<TenantPackage>> list() {
        List<TenantPackage> packages = tenantPackageService.listAvailablePackages();
        return success(packages);
    }

    @Operation(summary = "根据ID查询套餐详情")
    @GetMapping("/{id}")
    public ApiResult<TenantPackage> getById(@PathVariable("id") Integer id) {
        TenantPackage tenantPackage = tenantPackageService.getById(id);
        if (tenantPackage == null) {
            return fail("套餐不存在", null);
        }
        return success(tenantPackage);
    }

    @Operation(summary = "根据版本号查询套餐")
    @GetMapping("/version/{version}")
    public ApiResult<TenantPackage> getByVersion(@PathVariable("version") Integer version) {
        TenantPackage tenantPackage = tenantPackageService.getByVersion(version);
        if (tenantPackage == null) {
            return fail("套餐不存在", null);
        }
        return success(tenantPackage);
    }
}
