package de.oaa.xxx.games.chastity.lockcontroll;

import de.oaa.xxx.games.chastity.ttlock.TTLockConfigRepository;
import de.oaa.xxx.games.chastity.ttlock.TTLockUserConfigRepository;
import de.oaa.xxx.games.chastity.ttlock.TTAuthService;
import de.oaa.xxx.games.chastity.ttlock.TTLockService;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class LockControlFactory {

    private final TTAuthService ttAuthService;
    private final TTLockService ttLockService;
    private final TTLockConfigRepository ttLockConfigRepository;
    private final TTLockUserConfigRepository ttLockUserConfigRepository;

    public LockControlFactory(TTAuthService ttAuthService,
                               TTLockService ttLockService,
                               TTLockConfigRepository ttLockConfigRepository,
                               TTLockUserConfigRepository ttLockUserConfigRepository) {
        this.ttAuthService = ttAuthService;
        this.ttLockService = ttLockService;
        this.ttLockConfigRepository = ttLockConfigRepository;
        this.ttLockUserConfigRepository = ttLockUserConfigRepository;
    }

    public LockControl create(LockControllType type, LockControlCallback callback, UUID lockeeId) {
        return switch (type != null ? type : LockControllType.UNLOCK_CODE) {
            case TRUST -> new TrustLockControl();
            case TTLOCK -> new TTLockControl(
                    ttAuthService,
                    ttLockService,
                    ttLockConfigRepository.findById(1L).orElse(null),
                    ttLockUserConfigRepository.findById(lockeeId).orElse(null),
                    ttLockUserConfigRepository,
                    callback);
            case UNLOCK_CODE -> new UnlockcodeLockControl(callback);
        };
    }
}
