export type ParsedSeriesFilename = {
	title: string;
	season: number;
	episode: number;
};

export class SeriesNamings {
	async parseFilename(filename: string): Promise<ParsedSeriesFilename | null> {
		const match = filename
			.trim()
			.match(
				/^(?<title>.+?)(?:\s*[-._]\s*)?S(?<season>\d{2})E(?<episode>\d{2})/i,
			);
		if (!match || !match.groups) {
			return null;
		}

		const title = match.groups.title.trim();
		const season = Number.parseInt(match.groups.season, 10);
		const episode = Number.parseInt(match.groups.episode, 10);
		if (Number.isNaN(season) || Number.isNaN(episode)) {
			return null;
		}

		return { title, season, episode };
	}
}
