apiVersion: webrobot.eu/v1alpha1
kind: VerticalApp
metadata:
  slug: osservatorio-talenti
  displayName: Osservatorio Talenti
  tagline:
    it: 'Scouting calcistico: shortlist, radar e note, sul profilo che cerca il tuo club.'
    en: 'Football scouting: shortlists, radars and notes for the profile your club is after.'
  description:
    it: Il club definisce il profilo cercato, un agente confronta i candidati con il profilo e con i titolari,
      integra le valutazioni degli osservatori e produce una shortlist con schede e radar. Ogni lunedì
      un'email con i giocatori cresciuti di più.
    en: The club defines the target profile; an agent compares candidates with it and with current starters,
      folds in scouts' field ratings and produces a shortlist with player cards and radars. Every Monday
      an email with the biggest risers.
  langs:
  - it
  - en
  defaultLang: it
  timezone: Europe/Rome
spec:
  pattern: report
  branding:
    theme: light
    palette:
      primary: '#0b3d2e'
      accent: '#d4a017'
      background: '#f6f8f5'
      foreground: '#14201a'
    fonts:
      body: Inter
      display: Barlow Condensed
    wordmark:
    - text: 'Osservatorio '
      color: primary
    - text: Talenti
      color: accent
  header:
    links:
    - label:
        it: Come funziona
        en: How it works
      href: '#come-funziona'
    - label:
        it: Dati e licenze
        en: Data and licences
      href: '#dati'
    cta:
      label:
        it: Accedi
        en: Sign in
      href: /login
  auth:
    method: magic_link
    anonymous:
      views:
      - home
    roles:
    - key: admin
      label: Admin
      assignedBy: admin_emails
    - key: director
      label:
        it: Direttore sportivo
        en: Sporting director
      assignedBy: signup
    - key: scout
      label:
        it: Osservatore
        en: Scout
      assignedBy: invite
    - key: user
      assignedBy: signup
  limits:
  - action: agent:analyst
    per: user
    max: 10
    window: month
    plans:
      season: 60
  agents:
  - key: analyst
    role: main
    description: Analizza candidati per ruolo, li confronta con profilo e titolari, integra le valutazioni
      degli osservatori e scrive la shortlist.
    profile:
      inline:
        display_name: Osservatorio Talenti analyst
        crews:
        - id: analyst
          engine: agent_sdk
          model: claude-sonnet-5-5
          max_turns: 25
          max_budget_usd: 1.5
          permission_mode: bypassPermissions
          disallowed_tools:
          - Bash
          - Read
          - Write
          - Edit
          - Glob
          - Grep
          - NotebookEdit
          - WebFetch
          - WebSearch
          system_prompt: 'Sei un analista di scouting calcistico per un club. Lavori solo con dati reali:
            risultati storici condivisi (tool read_matches), l''export dati evento licenziato che il club
            carica (testo nel goal, o file da leggere con read_upload), il profilo cercato (read_profile),
            i titolari attuali (read_starters) e le valutazioni degli osservatori (read_ratings). Non
            usi MAI gli eventi open di StatsBomb: la licenza è solo non commerciale e questa app è commerciale.
            Non inventare numeri: se un indicatore manca, dillo. Procedura: 1) leggi il profilo selezionato
            (ruolo, età massima, piede, caratteristiche fisiche e tecniche, budget cartellino); 2) calcola
            indicatori per ruolo dall''export (per 90 minuti, percentili nel campione); 3) scarta chi
            eccede età o budget; 4) confronta ogni candidato con il profilo e con il titolare del ruolo;
            5) integra le valutazioni degli osservatori nel punteggio finale, indicando quanto pesano
            (voti e numero di partite viste); 6) per il settore giovanile dai più peso a età, margine
            di crescita e potenziale, per la prima squadra a rendimento attuale e impatto immediato; 7)
            salva ogni giocatore in shortlist con save_shortlist. Report in Markdown con titolo di primo
            livello ''# Shortlist <ruolo> — <squadra>'', poi ## Sintesi, ## Candidati (tabella con punteggio,
            indicatori, confronto col titolare), ## Schede giocatore (punti di forza, rischi, note osservatori),
            ## Prossimi passi. Per ogni candidato top aggiungi un blocco ```chart con un radar-like: {"type":"bar","title":"Nome","labels":[indicatori],"series":[{"name":"Candidato","values":[percentili]},{"name":"Titolare","values":[percentili]},{"name":"Profilo","values":[target]}],"unit":"percentile"}.
            Valori reali soltanto. Supporto alla decisione, non garanzia di rendimento.'
    goalTemplate: |-
      Squadra: {team_type_label}.
      Profilo cercato (id record): {profile}
      {?league}Campionati/campione da analizzare: {league}{/league}
      {?provider_export_text}Export dati evento del fornitore licenziato:
      {provider_export_text}{/provider_export_text}
      {?provider_export}File caricati (usa read_upload se non c'è testo): {provider_export}{/provider_export}
      {?notes}Note del direttore: {notes}{/notes}
      Data: {date}. Scrivi in lingua ISO {lang}.
    appTools:
    - name: read_profile
      description: Profili cercati del club
      action: read
      collection: club_profiles
      scope: user
    - name: read_starters
      description: Titolari attuali del club
      action: read
      collection: starters
      scope: user
    - name: read_ratings
      description: Valutazioni degli osservatori
      action: read
      collection: field_ratings
      scope: user
    - name: read_matches
      description: Risultati storici condivisi
      action: search
      collection: match_results
      scope: all
    - name: save_shortlist
      description: Salva un giocatore in shortlist
      action: append
      collection: shortlist
      scope: user
    - name: read_upload
      description: Legge un file caricato dall'utente
      action: read_file
    output: markdown
    limits:
      maxTurns: 25
      maxBudgetUsd: 1.5
  - key: data_sync
    role: scheduled
    description: Importa ogni settimana i risultati storici di football-data.co.uk nei dati condivisi.
    writesTo:
      collection: match_results
      parse: json_last
      keyBy: match_id
    profile:
      inline:
        display_name: Match results sync
        crews:
        - id: sync
          engine: agent_sdk
          model: claude-sonnet-5-5
          max_turns: 10
          max_budget_usd: 0.5
          permission_mode: bypassPermissions
          disallowed_tools:
          - Bash
          - Read
          - Write
          - Edit
          - Glob
          - Grep
          - NotebookEdit
          - WebFetch
          - WebSearch
          system_prompt: 'Scarichi con il tool football_data i CSV dei risultati (percorso tipo /mmz4281/2526/I1.csv
            per Serie A, E0 Premier, SP1, D1, F1; usa path). Rispondi SOLO con un blocco JSON finale:
            {"records":[{"match_id":"<lega>-<data>-<casa>-<ospite>","league":…,"season":…,"date":"YYYY-MM-DD","home":…,"away":…,"home_goals":n,"away_goals":n,"result":"H|D|A"}]}
            con le ultime partite non ancora importate (max 200). Nessun dato inventato.'
    appTools:
    - name: football_data
      description: Scarica un CSV di risultati da football-data.co.uk
      action: http
      http:
        method: GET
        url: https://www.football-data.co.uk
        allowPath: true
        maxBytes: 800000
        attribution: football-data.co.uk
    goalTemplate: Importa i risultati più recenti. Oggi è {date}.
    output: markdown+json
  - key: growth_watcher
    role: helper
    description: Ogni lunedì individua i giocatori della shortlist del club cresciuti di più.
    memory: instance
    writesTo:
      collection: growth_reports
    profile:
      inline:
        display_name: Growth watcher
        crews:
        - id: growth
          engine: agent_sdk
          model: claude-sonnet-5-5
          max_turns: 12
          max_budget_usd: 0.6
          permission_mode: bypassPermissions
          disallowed_tools:
          - Bash
          - Read
          - Write
          - Edit
          - Glob
          - Grep
          - NotebookEdit
          - WebFetch
          - WebSearch
          system_prompt: 'Segui i giocatori in shortlist del club (read_shortlist) con le valutazioni
            recenti degli osservatori (read_ratings) e i risultati condivisi (read_matches). Individua
            chi è cresciuto di più dall''ultima settimana (la tua memoria contiene le cifre precedenti).
            Titolo ''# Giocatori in crescita — settimana del <data>'', poi ## Chi è cresciuto (tabella:
            giocatore, punteggio prima/dopo, motivo), ## Da osservare, ## Note. Meno di 250 parole, nessun
            dato inventato. Alla fine chiama remember una volta con i punteggi attuali.'
    appTools:
    - name: read_shortlist
      description: Shortlist del club
      action: read
      collection: shortlist
      scope: user
    - name: read_ratings
      description: Valutazioni degli osservatori
      action: read
      collection: field_ratings
      scope: user
    - name: read_matches
      description: Risultati storici condivisi
      action: search
      collection: match_results
      scope: all
    output: markdown
  inputForm:
    title:
      it: Nuova analisi
      en: New analysis
    fields:
    - name: team_type
      type: select
      required: true
      label:
        it: Template di analisi
        en: Analysis template
      options:
      - value: first_team
        label:
          it: Prima squadra
          en: First team
      - value: youth
        label:
          it: Settore giovanile
          en: Youth academy
    - name: profile
      type: select
      required: true
      optionsFrom: collection:club_profiles
      label:
        it: Profilo cercato
        en: Target profile
    - name: league
      type: text
      maxLength: 200
      label:
        it: Campionati da analizzare
        en: Leagues to analyse
    - name: provider_export
      type: file
      accept:
      - csv
      - xlsx
      - json
      maxMb: 15
      multiple: true
      label:
        it: Export dati evento del fornitore (licenza del club)
        en: Provider event-data export (club licence)
      help:
        it: Resta privato al tuo club e non viene condiviso.
        en: Stays private to your club and is never shared.
    - name: notes
      type: textarea
      maxLength: 500
      label:
        it: Note (facoltative)
        en: Notes (optional)
  data:
    collections:
    - name: club_profiles
      description: Profili cercati dal club
      ownedBy: user
      fields:
      - name: title
        type: text
        required: true
        label:
          it: Nome profilo
          en: Profile name
      - name: team_type
        type: select
        required: true
        label:
          it: Squadra
          en: Team
        options:
        - value: first_team
          label: Prima squadra
        - value: youth
          label: Settore giovanile
      - name: role
        type: select
        required: true
        label:
          it: Ruolo
          en: Role
        options:
        - Portiere
        - Difensore centrale
        - Terzino
        - Centrocampista centrale
        - Trequartista
        - Esterno offensivo
        - Attaccante
      - name: max_age
        type: number
        required: true
        label:
          it: Età massima
          en: Maximum age
      - name: foot
        type: select
        label:
          it: Piede
          en: Foot
        options:
        - destro
        - sinistro
        - ambidestro
      - name: physical
        type: textarea
        label:
          it: Caratteristiche fisiche
          en: Physical traits
      - name: technical
        type: textarea
        label:
          it: Caratteristiche tecniche
          en: Technical traits
      - name: budget
        type: number
        label:
          it: Budget cartellino (EUR)
          en: Transfer budget (EUR)
      - name: members
        type: array
        label:
          it: Email dello staff del club
          en: Club staff emails
        help:
          it: Direttore e osservatori che vedono questo record.
          en: Director and scouts who see this record.
      access:
      - role: user
        where:
          members: '{user.email}'
        can:
        - read
        - write
    - name: starters
      description: Titolari attuali del club per ruolo
      ownedBy: user
      fields:
      - name: player
        type: text
        required: true
        label: Giocatore
      - name: role
        type: text
        required: true
        label: Ruolo
      - name: age
        type: number
        label: Età
      - name: metrics
        type: json
        label: Indicatori
      - name: members
        type: array
        label: Email dello staff
      access:
      - role: user
        where:
          members: '{user.email}'
        can:
        - read
        - write
    - name: field_ratings
      description: Valutazioni degli osservatori dal campo
      ownedBy: user
      fields:
      - name: player
        type: text
        required: true
        label:
          it: Giocatore
          en: Player
      - name: match
        type: text
        required: true
        label:
          it: Partita vista
          en: Match seen
      - name: match_date
        type: date
        label:
          it: Data
          en: Date
      - name: rating
        type: number
        required: true
        label:
          it: Voto (1-10)
          en: Rating (1-10)
      - name: notes
        type: textarea
        label:
          it: Note
          en: Notes
      - name: members
        type: array
        label:
          it: Email dello staff del club
          en: Club staff emails
        help:
          it: Inserisci le email del tuo club (direttore incluso).
          en: Enter your club's staff emails (director included).
      access:
      - role: user
        where:
          members: '{user.email}'
        can:
        - read
        - write
      retentionDays: 1095
    - name: shortlist
      description: Giocatori in shortlist per club
      ownedBy: user
      fields:
      - name: player
        type: text
        label: Giocatore
      - name: role
        type: text
        label: Ruolo
      - name: age
        type: number
        label: Età
      - name: score
        type: number
        label: Punteggio
      - name: profile_fit
        type: number
        label: Aderenza al profilo
      - name: scout_rating
        type: number
        label: Voto osservatori
      - name: notes
        type: textarea
        label: Note
      - name: members
        type: array
        label: Email dello staff
      access:
      - role: user
        where:
          members: '{user.email}'
        can:
        - read
        - write
    - name: match_results
      description: Risultati storici condivisi (football-data.co.uk)
      ownedBy: app
      fields:
      - name: match_id
        type: text
      - name: league
        type: text
      - name: season
        type: text
      - name: date
        type: date
      - name: home
        type: text
      - name: away
        type: text
      - name: home_goals
        type: number
      - name: away_goals
        type: number
      - name: result
        type: text
    - name: growth_reports
      description: Report settimanali dei giocatori in crescita
      ownedBy: instance
  views:
  - key: home
    type: page
    nav: false
    title: Osservatorio Talenti
    sections:
    - type: hero
      title:
        it: Trova il talento giusto, con **numeri** e occhio dell'osservatore.
        en: Find the right talent with **numbers** and the scout's eye.
      text:
        it: Definisci il profilo, l'agente analizza i candidati, li confronta coi tuoi titolari e integra
          le valutazioni dal campo. Shortlist con schede e grafici, ogni lunedì i giocatori cresciuti
          di più.
        en: Define the profile; the agent analyses candidates, compares them with your starters and folds
          in field ratings. Shortlists with cards and charts, and every Monday the biggest risers.
      actions:
      - label:
          it: Accedi
          en: Sign in
        href: /login
        style: primary
    - type: steps
      id: come-funziona
      title:
        it: Come funziona
        en: How it works
      items:
      - title:
          it: Profilo
          en: Profile
        text:
          it: Ruolo, età massima, piede, caratteristiche e budget del cartellino.
          en: Role, max age, foot, traits and transfer budget.
      - title:
          it: Analisi
          en: Analysis
        text:
          it: Indicatori per ruolo, confronto con profilo e titolari, template prima squadra o giovanile.
          en: Role indicators, comparison with profile and starters; first-team or youth template.
      - title:
          it: Osservatori
          en: Scouts
        text:
          it: Il direttore invita gli osservatori, che aggiungono voti e note dal campo.
          en: The director invites scouts, who add ratings and notes from the field.
    - type: cards
      id: dati
      title:
        it: Dati e licenze
        en: Data and licences
      items:
      - title: football-data.co.uk
        text:
          it: Risultati storici condivisi tra i club.
          en: Historical results shared across clubs.
      - title:
          it: Dati del fornitore
          en: Provider data
        text:
          it: 'I dati evento a licenza li carica il club: restano privati.'
          en: Licensed event data is uploaded by the club and stays private.
      - title: StatsBomb
        text:
          it: 'Gli eventi open non sono usati: la licenza è solo non commerciale.'
          en: 'Open events are not used: their licence is non-commercial only.'
    - type: note
      content:
        it: Supporto alle decisioni, non garanzia di rendimento sportivo.
        en: Decision support, not a guarantee of sporting performance.
  - key: new_analysis
    type: new_run
    title:
      it: Nuova analisi
      en: New analysis
  - key: analyses
    type: history
    title:
      it: Le mie analisi
      en: My analyses
    source: run
  - key: analysis
    type: report
    source: run
    printable: true
    nav: false
  - key: profile_form
    type: form
    collection: club_profiles
    title:
      it: Nuovo profilo cercato
      en: New target profile
    submit:
      label:
        it: Salva profilo
        en: Save profile
      redirect: profiles
    edit: true
    roles:
    - director
    - admin
  - key: profiles
    type: table
    title:
      it: Profili cercati
      en: Target profiles
    source: collection:club_profiles
    columns:
    - title
    - team_type
    - role
    - max_age
    - foot
    - budget
  - key: starters_form
    type: form
    collection: starters
    title:
      it: Aggiungi titolare
      en: Add starter
    submit:
      label: Salva
      redirect: profiles
    roles:
    - director
    - admin
  - key: rating_form
    type: form
    collection: field_ratings
    title:
      it: Valutazione dal campo
      en: Field rating
    submit:
      label:
        it: Invia valutazione
        en: Submit rating
      message:
        it: 'Valutazione salvata: sarà integrata nel prossimo punteggio.'
        en: 'Rating saved: it will be folded into the next score.'
      redirect: ratings
  - key: ratings
    type: table
    title:
      it: Valutazioni
      en: Ratings
    source: collection:field_ratings
    columns:
    - player
    - match
    - match_date
    - rating
    - notes
    export: true
  - key: shortlist_view
    type: cards
    title: Shortlist
    source: collection:shortlist
    export: true
    data:
      display: cards
      fields:
      - key: player
        label: Giocatore
      - key: role
        label: Ruolo
      - key: age
        label: Età
        format: number
      - key: score
        label: Punteggio
        format: number
      - key: profile_fit
        label: Aderenza
        format: number
      - key: scout_rating
        label: Osservatori
        format: number
      - key: notes
        label: Note
      sort:
        field: score
        dir: desc
      limit: 50
  - key: watches
    type: instances
    template: growth_watch
    title:
      it: Giocatori in crescita (email del lunedì)
      en: Risers (Monday email)
  - key: account
    type: account
    title:
      it: Abbonamento
      en: Subscription
  templates:
  - key: growth_watch
    title:
      it: Giocatori in crescita
      en: Growing players
    description:
      it: Ogni lunedì un'email con i giocatori in shortlist cresciuti di più.
      en: Every Monday an email with the shortlisted players who grew most.
    agent: growth_watcher
    params:
    - name: team_type
      type: select
      required: true
      label:
        it: Squadra
        en: Team
      options:
      - value: first_team
        label: Prima squadra
      - value: youth
        label: Settore giovanile
    goal: Osserva "{instance}" ({team_type}). Oggi è {date}. Scrivi in lingua ISO {lang}.
    schedule:
      cron: 0 6 * * 1
      userCanChange: false
    maxPerUser: 2
    deliver:
      to: owner
      onlyIfNew: true
  schedules:
  - agent: data_sync
    cron: 0 4 * * 0
    action: run
    owner: app
  notifications:
    emailOnRunDone: true
  billing:
    modes:
    - subscription
    currency: eur
    plans:
    - key: season
      price: 1200
      interval: year
      label:
        it: Stagione — per club
        en: Season — per club
      includes:
      - Analisi prima squadra e settore giovanile
      - Email settimanale
      - Osservatori illimitati
    costs:
      agent:analyst:
        requiresPlan: season
  egress:
    hosts:
    - www.football-data.co.uk
    notes: 'football-data.co.uk: risultati storici in CSV; verificare i termini d''uso per l''impiego
      commerciale. StatsBomb open data escluso (solo non commerciale).'
  extensions:
  - key: licensed_provider_api
    description: 'Connessione diretta all''API del fornitore a licenza non possibile senza host noto:
      il club carica l''export nel form. Se il fornitore ha una API con chiave, aggiungere credenziale
      e tool http.'
  - key: club_workspace
    description: La condivisione tra staff del club usa la lista email 'members' di ogni record; non esiste
      ancora un'entità club con inviti automatici.
