package com.aip.gateway.api.service.impl;

import com.aip.gateway.api.model.request.RequestFile;
import com.aip.gateway.api.model.request.RequestFileAllSet;
import com.aip.gateway.api.model.request.RequestFileDel;
import com.aip.gateway.api.model.request.RequestFileSet;
import com.aip.gateway.api.model.response.ResponseFile;
import com.aip.gateway.api.model.response.ResponseInfo;
import com.aip.gateway.api.repository.AipFileRepository;
import com.aip.gateway.api.repository.AppRepository;
import com.aip.gateway.api.service.IApiFileService;
import com.aip.gateway.api.aip.utils.AipFileUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ApiFileService extends AbstractAipService implements IApiFileService {

    public ApiFileService(AppRepository repo, AipFileRepository aipFile) {
        super(repo, aipFile);
    }

    @Override
    public ResponseInfo getInfo(RequestFile req) {
        try {
            String reqFileName = getRequestFileName(req.getRealFileName());
            if (!AipFileUtils.isExists(reqFileName)) {
                return new ResponseInfo(101, "파일이 존재하지 않습니다.");
            }
            String newFileExt = getSupportedFileType(reqFileName);
            if (newFileExt == null) {
                return new ResponseInfo(102, "지원하지 않는 파일형식 입니다.");
            }
            return responseGetFileInfo(this.aipFile.getManager().getFileInfo(reqFileName), req.getDispFileName());
        }
        catch (Exception e) {
            return new ResponseInfo(109, "작업 중에 시스템 오류가 발생했습니다.");
        }
    }

    @Override
    public ResponseFile setLabel(RequestFileSet req) {
        return null;
    }

    @Override
    public ResponseFile delLabel(RequestFileDel req) {
        return null;
    }

    @Override
    public ResponseFile setProtection(RequestFileSet req) {
        return null;
    }

    @Override
    public ResponseFile delProtection(RequestFileDel req) {
        return null;
    }

    @Override
    public ResponseFile setLabelProtection(RequestFileAllSet req) {
        return null;
    }

    @Override
    public ResponseFile delLabelProtection(RequestFileDel req) {
        return null;
    }
}
