package org.springblade.common.upyzt.model;

import org.springblade.common.upyzt.exception.UpyztException;
import org.springblade.common.upyzt.net.APIResource;
import org.springblade.common.upyzt.net.RequestOptions;
import org.springblade.common.upyzt.resp.MediaResp;
import lombok.experimental.Accessors;

import java.io.File;

@Accessors(chain = true)
public class Media extends APIResource {

    /**
     * 图片上传
     *
     * @param file 图片文件
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static MediaResp uploadImage(File file) throws UpyztException {
        return uploadImage(file, null);
    }

    /**
     * 图片上传
     *
     * @param file    图片文件
     * @param options 参数选项
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static MediaResp uploadImage(File file, RequestOptions options) throws UpyztException {
        return APIResource.uploadFile(RequestMethod.POST, singleClassURL(Media.class) + "/images", file, MediaResp.class, options);
    }

}
