import type { ProviderDescriptor } from './types';

export const googlePhotosDescriptor: ProviderDescriptor = {
	type: 'google_photos',
	defaultName: 'Google Photos',
	icon: 'mdiGoogle',
	hasUrl: false,

	configFields: [
		{
			key: 'gp_client_id', configKey: 'client_id',
			label: 'providers.gpClientId', type: 'text',
			required: 'create-only', placeholder: '123456789.apps.googleusercontent.com',
		},
		{
			key: 'gp_client_secret', configKey: 'client_secret',
			label: 'providers.gpClientSecret', editLabel: 'providers.gpClientSecretKeep',
			type: 'password', required: 'create-only',
		},
		{
			key: 'gp_refresh_token', configKey: 'refresh_token',
			label: 'providers.gpRefreshToken', editLabel: 'providers.gpRefreshTokenKeep',
			type: 'password', required: 'create-only', hint: 'providers.gpRefreshTokenHint',
		},
	],

	buildConfig(form, editing) {
		const config: Record<string, any> = {};
		if (form.gp_client_id) config.client_id = form.gp_client_id;
		if (form.gp_client_secret) config.client_secret = form.gp_client_secret;
		if (form.gp_refresh_token) config.refresh_token = form.gp_refresh_token;
		if (!editing && (!form.gp_client_id || !form.gp_client_secret || !form.gp_refresh_token)) {
			return { config, error: 'providers.gpAllFieldsRequired' };
		}
		return { config };
	},

	hasConfigChanged(form, existing) {
		return form.gp_client_id !== (existing.client_id || '') ||
			!!form.gp_client_secret || !!form.gp_refresh_token;
	},

	eventFields: [
		{ key: 'track_assets_added', label: 'trackingConfig.assetsAdded', default: true },
		{ key: 'track_assets_removed', label: 'trackingConfig.assetsRemoved', default: false },
		{ key: 'track_collection_renamed', label: 'trackingConfig.albumRenamed', default: true },
		{ key: 'track_collection_deleted', label: 'trackingConfig.albumDeleted', default: true },
		{ key: 'track_sharing_changed', label: 'trackingConfig.sharingChanged', default: false },
	],

	collectionMeta: {
		label: 'notificationTracker.albums',
		icon: 'mdiGoogle',
		placeholder: 'notificationTracker.selectAlbums',
		countLabel: 'notificationTracker.albums_count',
		desc: (col) => `${col.assetCount ?? col.asset_count ?? col.mediaItemsCount ?? 0} items`,
	},
};
