import { ConnectorService } from '@sre/Core/ConnectorsService';
import { Logger } from '@sre/helpers/Log.helper';
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
import { ACL } from '@sre/Security/AccessControl/ACL.class';
import { SecureConnector } from '@sre/Security/SecureConnector.class';
import { IAccessCandidate, TAccessLevel, TAccessRole } from '@sre/types/ACL.types';
import { IVaultRequest, VaultConnector } from '../VaultConnector';

const console = Logger('HashicorpVault');
export class HashicorpVault extends VaultConnector {
    public name: string = 'HashicorpVault';

    constructor(protected _settings: any) {
        super(_settings);
        //hashicorp client/api
    }

    @SecureConnector.AccessControl
    protected async get(acRequest: AccessRequest, keyId: string) {
        return null;
    }

    @SecureConnector.AccessControl
    protected async exists(acRequest: AccessRequest, keyId: string) {
        return false;
    }

    @SecureConnector.AccessControl
    protected async listKeys(acRequest: AccessRequest) {
        return [];
    }

    public async getResourceACL(resourceId: string, candidate: IAccessCandidate) {
        //FIXME : this is for dev, it always give full access, we must update the logic
        const accountConnector = ConnectorService.getAccountConnector();
        const teamId = await accountConnector.getCandidateTeam(candidate);
        const acl = new ACL();

        acl.addAccess(TAccessRole.Team, teamId, TAccessLevel.Owner)
            .addAccess(TAccessRole.Team, teamId, TAccessLevel.Read)
            .addAccess(TAccessRole.Team, teamId, TAccessLevel.Write);

        return acl;
    }
}
