package com.agileboot.domain.collaboration.record.model;

import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode.Business;
import com.agileboot.domain.collaboration.record.db.CollaborationRecordEntity;
import com.agileboot.domain.collaboration.record.db.CollaborationRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @author codex
 */
@Component
@RequiredArgsConstructor
public class CollaborationRecordModelFactory {

    private final CollaborationRecordService recordService;

    public CollaborationRecordModel loadById(Long recordId) {
        CollaborationRecordEntity entity = recordService.getById(recordId);
        if (entity == null) {
            throw new ApiException(Business.COMMON_OBJECT_NOT_FOUND, recordId, "合作记录");
        }
        return new CollaborationRecordModel(entity, recordService);
    }

    public CollaborationRecordModel create() {
        return new CollaborationRecordModel(recordService);
    }

}
