// Kyoo - A portable and vast media library solution.
// Copyright (c) Kyoo.
//
// See AUTHORS.md and LICENSE file in the project root for full license information.
//
// Kyoo is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// Kyoo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see .
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Kyoo.Abstractions.Models;
using Kyoo.Abstractions.Models.Exceptions;
namespace Kyoo.Abstractions.Controllers
{
///
/// A common repository for every resources.
///
/// The resource's type that this repository manage.
public interface IRepository : IBaseRepository
where T : class, IResource
{
///
/// The event handler type for all events of this repository.
///
/// The resource created/modified/deleted
public delegate void ResourceEventHandler(T resource);
///
/// Get a resource from it's ID.
///
/// The id of the resource
/// If the item could not be found.
/// The resource found
Task Get(int id);
///
/// Get a resource from it's slug.
///
/// The slug of the resource
/// If the item could not be found.
/// The resource found
Task Get(string slug);
///
/// Get the first resource that match the predicate.
///
/// A predicate to filter the resource.
/// If the item could not be found.
/// The resource found
Task Get(Expression> where);
///
/// Get a resource from it's ID or null if it is not found.
///
/// The id of the resource
/// The resource found
Task GetOrDefault(int id);
///
/// Get a resource from it's slug or null if it is not found.
///
/// The slug of the resource
/// The resource found
Task GetOrDefault(string slug);
///
/// Get the first resource that match the predicate or null if it is not found.
///
/// A predicate to filter the resource.
/// A custom sort method to handle cases where multiples items match the filters.
/// The resource found
Task GetOrDefault(Expression> where, Sort? sortBy = default);
///
/// Search for resources.
///
/// The query string.
/// A list of resources found
Task> Search(string query);
///
/// Get every resources that match all filters
///
/// A filter predicate
/// Sort information about the query (sort by, sort order)
/// How pagination should be done (where to start and how many to return)
/// A list of resources that match every filters
Task> GetAll(Expression>? where = null,
Sort? sort = default,
Pagination? limit = default);
///
/// Get the number of resources that match the filter's predicate.
///
/// A filter predicate
/// How many resources matched that filter
Task GetCount(Expression>? where = null);
///
/// Create a new resource.
///
/// The item to register
/// The resource registers and completed by database's information (related items and so on)
Task Create(T obj);
///
/// Create a new resource if it does not exist already. If it does, the existing value is returned instead.
///
/// The object to create
/// The newly created item or the existing value if it existed.
Task CreateIfNotExists(T obj);
///
/// Called when a resource has been created.
///
event ResourceEventHandler OnCreated;
///
/// Edit a resource
///
/// The resource to edit, it's ID can't change.
/// Should old properties of the resource be discarded or should null values considered as not changed?
/// If the item is not found
/// The resource edited and completed by database's information (related items and so on)
Task Edit(T edited, bool resetOld);
///
/// Called when a resource has been edited.
///
event ResourceEventHandler OnEdited;
///
/// Delete a resource by it's ID
///
/// The ID of the resource
/// If the item is not found
/// A representing the asynchronous operation.
Task Delete(int id);
///
/// Delete a resource by it's slug
///
/// The slug of the resource
/// If the item is not found
/// A representing the asynchronous operation.
Task Delete(string slug);
///
/// Delete a resource
///
/// The resource to delete
/// If the item is not found
/// A representing the asynchronous operation.
Task Delete(T obj);
///
/// Delete all resources that match the predicate.
///
/// A predicate to filter resources to delete. Every resource that match this will be deleted.
/// A representing the asynchronous operation.
Task DeleteAll(Expression> where);
///
/// Called when a resource has been edited.
///
event ResourceEventHandler OnDeleted;
}
///
/// A base class for repositories. Every service implementing this will be handled by the .
///
public interface IBaseRepository
{
///
/// The type for witch this repository is responsible or null if non applicable.
///
Type RepositoryType { get; }
}
///
/// A repository to handle shows.
///
public interface IMovieRepository : IRepository { }
///
/// A repository to handle shows.
///
public interface IShowRepository : IRepository
{
///
/// Get a show's slug from it's ID.
///
/// The ID of the show
/// If a show with the given ID is not found.
/// The show's slug
Task GetSlug(int showID);
}
///
/// A repository to handle seasons.
///
public interface ISeasonRepository : IRepository
{
///
/// Get a season from it's showID and it's seasonNumber
///
/// The id of the show
/// The season's number
/// If the item is not found
/// The season found
Task Get(int showID, int seasonNumber);
///
/// Get a season from it's show slug and it's seasonNumber
///
/// The slug of the show
/// The season's number
/// If the item is not found
/// The season found
Task Get(string showSlug, int seasonNumber);
///
/// Get a season from it's showID and it's seasonNumber or null if it is not found.
///
/// The id of the show
/// The season's number
/// The season found
Task GetOrDefault(int showID, int seasonNumber);
///
/// Get a season from it's show slug and it's seasonNumber or null if it is not found.
///
/// The slug of the show
/// The season's number
/// The season found
Task GetOrDefault(string showSlug, int seasonNumber);
}
///
/// The repository to handle episodes
///
public interface IEpisodeRepository : IRepository
{
// TODO replace the next methods with extension methods.
///
/// Get a episode from it's showID, it's seasonNumber and it's episode number.
///
/// The id of the show
/// The season's number
/// The episode's number
/// If the item is not found
/// The episode found
Task Get(int showID, int seasonNumber, int episodeNumber);
///
/// Get a episode from it's show slug, it's seasonNumber and it's episode number.
///
/// The slug of the show
/// The season's number
/// The episode's number
/// If the item is not found
/// The episode found
Task Get(string showSlug, int seasonNumber, int episodeNumber);
///
/// Get a episode from it's showID, it's seasonNumber and it's episode number or null if it is not found.
///
/// The id of the show
/// The season's number
/// The episode's number
/// The episode found
Task GetOrDefault(int showID, int seasonNumber, int episodeNumber);
///
/// Get a episode from it's show slug, it's seasonNumber and it's episode number or null if it is not found.
///
/// The slug of the show
/// The season's number
/// The episode's number
/// The episode found
Task GetOrDefault(string showSlug, int seasonNumber, int episodeNumber);
///
/// Get a episode from it's showID and it's absolute number.
///
/// The id of the show
/// The episode's absolute number (The episode number does not reset to 1 after the end of a season.
/// If the item is not found
/// The episode found
Task GetAbsolute(int showID, int absoluteNumber);
///
/// Get a episode from it's showID and it's absolute number.
///
/// The slug of the show
/// The episode's absolute number (The episode number does not reset to 1 after the end of a season.
/// If the item is not found
/// The episode found
Task GetAbsolute(string showSlug, int absoluteNumber);
}
///
/// A repository to handle library items (A wrapper around shows and collections).
///
public interface ILibraryItemRepository : IRepository { }
///
/// A repository for collections
///
public interface ICollectionRepository : IRepository { }
///
/// A repository for studios.
///
public interface IStudioRepository : IRepository { }
///
/// A repository for people.
///
public interface IPeopleRepository : IRepository
{
///
/// Get people's roles from a show.
///
/// The ID of the show
/// A filter function
/// Sort information (sort order and sort by)
/// How many items to return and where to start
/// No exist with the given ID.
/// A list of items that match every filters
Task> GetFromShow(int showID,
Expression>? where = null,
Sort? sort = default,
Pagination? limit = default);
///
/// Get people's roles from a show.
///
/// The slug of the show
/// A filter function
/// Sort information (sort order and sort by)
/// How many items to return and where to start
/// No exist with the given slug.
/// A list of items that match every filters
Task> GetFromShow(string showSlug,
Expression>? where = null,
Sort? sort = default,
Pagination? limit = default);
///
/// Get people's roles from a person.
///
/// The id of the person
/// A filter function
/// Sort information (sort order and sort by)
/// How many items to return and where to start
/// No exist with the given ID.
/// A list of items that match every filters
Task> GetFromPeople(int id,
Expression>? where = null,
Sort? sort = default,
Pagination? limit = default);
///
/// Get people's roles from a person.
///
/// The slug of the person
/// A filter function
/// Sort information (sort order and sort by)
/// How many items to return and where to start
/// No exist with the given slug.
/// A list of items that match every filters
Task> GetFromPeople(string slug,
Expression>? where = null,
Sort? sort = default,
Pagination? limit = default);
}
///
/// A repository to handle users.
///
public interface IUserRepository : IRepository { }
}