o
    !\i                     @   sJ   d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 G dd dZ
dS )	zTeam repository    )OptionalList)Session)Team)LeagueRepositoryc                	   @   s   e Zd ZdZdefddZdedee fddZ	d	e
dee fd
dZde
dee fddZdedefddZdd	e
de
dee
 defddZdS )TeamRepositoryzRepository for team operationsdbc                 C   s
   || _ d S N)r   )selfr    r   +app/core/db/repositories/team_repository.py__init__   s   
zTeamRepository.__init__team_idreturnc                 C      | j ttj|k S )zGet team by ID)r   queryr   filteridfirst)r
   r   r   r   r   	get_by_id      zTeamRepository.get_by_id	source_idc                 C   r   )zGet team by source ID)r   r   r   r   r   r   )r
   r   r   r   r   get_by_source_id   r   zTeamRepository.get_by_source_idnamec                 C   r   )zGet team by name)r   r   r   r   r   r   )r
   r   r   r   r   get_by_name   r   zTeamRepository.get_by_nameteamc                 C   s&   | j | | j   | j | |S )zCreate a new team)r   addcommitrefresh)r
   r   r   r   r   create   s   
zTeamRepository.createNcountryc                 C   sP   |  |}|r	|S d}|rt| j}||j}t|||d| d}| |S )zxGet or create team by source ID

        `country` is a country name from the source; we map it to `countries`.
        Nteam_)r   r   
country_idcode)r   r   r   get_or_create_countryr   r   r   )r
   r   r   r    r   r"   lrr   r   r   get_or_create_by_source_id!   s   


z)TeamRepository.get_or_create_by_source_idr	   )__name__
__module____qualname____doc__r   r   intr   r   r   strr   r   r   r&   r   r   r   r   r      s    $r   N)r*   typingr   r   sqlalchemy.ormr   app.core.db.models.teamr   *app.core.db.repositories.league_repositoryr   r   r   r   r   r   <module>   s    