<?php
// +----------------------------------------------------------------------
// | onezan-admin 快速开发的管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.onezan.cn
// +----------------------------------------------------------------------
// | onezan团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: 543885307@qq.com
// +----------------------------------------------------------------------
namespace app\adminapi\controller\media;

use app\adminapi\controller\BaseAdminController;
use app\service\admin\media\MediaService;
use think\Request;


/**
 * 媒体资源管理
 * 文件上传、列表、删除、分组管理
 * @package app\adminapi\controller\media
 */
class Media extends BaseAdminController
{
    /**
     * 上传文件
     * @param Request $request
     * @return \think\response\Json
     */
    public function upload(Request $request)
    {
        $result = $this->app->make(MediaService::class)->upload($request);
        $httpStatus = (int)($result['_http_status'] ?? 200);
        unset($result['_http_status']);
        return json($result, $httpStatus);
    }

    /**
     * 媒体资源列表
     * @param Request $request
     * @return \think\response\Json
     */
    public function list(Request $request)
    {
        return json($this->app->make(MediaService::class)->list($request));
    }

    /**
     * 删除媒体资源
     * @param Request $request
     * @return \think\response\Json
     */
    public function delete(Request $request)
    {
        return json($this->app->make(MediaService::class)->delete($request));
    }

    /**
     * 批量删除媒体资源
     * @param Request $request
     * @return \think\response\Json
     */
    public function deleteBatch(Request $request)
    {
        return json($this->app->make(MediaService::class)->deleteBatch($request));
    }

    /**
     * 媒体资源分组列表
     * @return \think\response\Json
     */
    public function groupList()
    {
        return json($this->app->make(MediaService::class)->groupList());
    }

    /**
     * 保存媒体资源分组
     * @param Request $request
     * @return \think\response\Json
     */
    public function groupSave(Request $request)
    {
        return json($this->app->make(MediaService::class)->groupSave($request));
    }

    /**
     * 删除媒体资源分组
     * @param Request $request
     * @return \think\response\Json
     */
    public function groupDelete(Request $request)
    {
        return json($this->app->make(MediaService::class)->groupDelete($request));
    }
}
