import { Query, Resolver } from '@nestjs/graphql';

import { AuthAction, Resource } from '@unraid/shared/graphql.model.js';
import { UsePermissions } from '@unraid/shared/use-permissions.directive.js';

import { getShares } from '@app/core/utils/shares/get-shares.js';
import { Share } from '@app/unraid-api/graph/resolvers/array/array.model.js';

@Resolver(() => Share)
export class SharesResolver {
    constructor() {}

    @Query(() => [Share])
    @UsePermissions({
        action: AuthAction.READ_ANY,
        resource: Resource.SHARE,
    })
    public async shares() {
        const userShares = getShares('users');
        const diskShares = getShares('disks');

        const shares = [...userShares, ...diskShares];

        return shares;
    }
}
