# seeds/lims/seed.yaml
#
# LIMS Seed — Next-Generation Sequencing LIMS
#
# Standard seeder contract:
#   - admin user: password Admin123!, role admin, verified
#   - role-specific demo users: password Demo123!, verified
#   - predictable data with stable names for deterministic tests
#   - idempotent: safe to run on every server start
#
# Execution order (four phases):
#   Phase 1 — Roles
#   Phase 2 — Users
#   Phase 3 — Assignments
#   Phase 4 — Domain data (projects, samples, instruments, protocols, runs, analyses)
#
# Note on M2M linking (Run ↔ Sample):
#   Run-to-sample links via the RunSamples junction table cannot be seeded
#   here because the seeder dispatches create actions that return auto-generated
#   UUIDs not known at seed-file authoring time. Use the API to link samples
#   to runs after the server has started.

# ─── Phase 1: Roles ─────────────────────────────────────────────

roles:
  - name: admin
    description: "Full system access. Can manage all resources, instruments, and users."

  - name: pi
    description: "Principal investigator. Can create projects, submit samples, and view all data."

  - name: lab_tech
    description: "Lab technician. Can process samples, operate instruments, run analyses, and transition state machines."

  - name: authenticated
    description: "Any authenticated user. Read-only access to list and view all resources."

# ─── Phase 2: Users ─────────────────────────────────────────────

users:
  - username: admin
    email: admin@lims.example.com
    password: "Admin123!"
    verified: true

  - username: dr_chen
    email: dr.chen@lims.example.com
    password: "Demo123!"
    verified: true

  - username: dr_patel
    email: dr.patel@lims.example.com
    password: "Demo123!"
    verified: true

  - username: maria
    email: maria.garcia@lims.example.com
    password: "Demo123!"
    verified: true

  - username: james
    email: james.oconnor@lims.example.com
    password: "Demo123!"
    verified: true

# ─── Phase 3: Assignments ───────────────────────────────────────

assignments:
  - username: admin
    roles: [admin]

  - username: dr_chen
    roles: [pi]

  - username: dr_patel
    roles: [pi]

  - username: maria
    roles: [lab_tech]

  - username: james
    roles: [lab_tech]

# ─── Phase 4: Domain data ───────────────────────────────────────
#
# Creation order respects foreign key dependencies:
#   1. Projects (no FK dependencies)
#   2. Instruments (no FK dependencies)
#   3. Protocols (no FK dependencies)
#   4. Samples (FK → Project)
#   5. Runs (FK → Instrument, FK → Protocol)
#   6. Analyses (FK → Run)
#
# Note: Run ↔ Sample links (belongsToMany via RunSamples) require
# UUIDs returned from create calls and must be linked via the API.

data:

  # ── Projects ───────────────────────────────────────────────────

  - action: adl.lims.project.create
    as: dr_chen
    data:
      name: "BRCA Whole Genome Sequencing"
      description: "30x whole genome sequencing of 48 breast cancer tumor/normal pairs for somatic variant discovery. Samples from the university biobank, IRB protocol #2025-0842."
      organism: human
      referenceGenome: "GRCh38"
      piName: "Dr. Wei Chen"
      piEmail: "dr.chen@lims.example.com"
      labName: "Chen Genomics Lab"
      department: "Molecular Oncology"
      grantNumber: "NIH-R01-CA-284719"
      sequencingObjective: "Whole Genome 30x"
      targetSampleCount: 96
      samplesReceived: 12
      samplesCompleted: 0
      startDate: "2026-02-15"
      targetDate: "2026-06-30"
      active: true
      notes: "Priority project — quarterly NIH progress report due July 15."

  - action: adl.lims.project.create
    as: dr_chen
    data:
      name: "Colorectal Organoid RNA-seq"
      description: "RNA-seq of patient-derived colorectal organoids treated with 6 drug combinations. 3 biological replicates per condition, 36 samples total."
      organism: human
      referenceGenome: "GRCh38"
      piName: "Dr. Wei Chen"
      piEmail: "dr.chen@lims.example.com"
      labName: "Chen Genomics Lab"
      department: "Molecular Oncology"
      grantNumber: "NIH-R01-CA-284719"
      sequencingObjective: "RNA-seq polyA, 50M reads"
      targetSampleCount: 36
      samplesReceived: 36
      samplesCompleted: 0
      startDate: "2026-03-01"
      targetDate: "2026-05-15"
      active: true

  - action: adl.lims.project.create
    as: dr_patel
    data:
      name: "Mouse Gut Microbiome 16S"
      description: "16S rRNA V3-V4 amplicon sequencing of mouse gut microbiome samples across 4 diet conditions. Longitudinal study with 5 time points."
      organism: mouse
      referenceGenome: "GRCm39"
      piName: "Dr. Anita Patel"
      piEmail: "dr.patel@lims.example.com"
      labName: "Patel Microbiome Lab"
      department: "Immunology"
      grantNumber: "NSF-MCB-2613847"
      sequencingObjective: "16S V3-V4 Amplicon, 100k reads/sample"
      targetSampleCount: 200
      samplesReceived: 50
      samplesCompleted: 0
      startDate: "2026-01-10"
      targetDate: "2026-09-30"
      active: true
      notes: "Staggered sample submission — 50 samples per month through May."

  - action: adl.lims.project.create
    as: dr_patel
    data:
      name: "E. coli Genome Assembly"
      description: "Long-read nanopore sequencing of 10 E. coli K-12 derivative strains for complete genome assembly. Comparing engineered vs. wild-type metabolic pathway variants."
      organism: ecoli
      referenceGenome: "K-12 MG1655"
      piName: "Dr. Anita Patel"
      piEmail: "dr.patel@lims.example.com"
      labName: "Patel Microbiome Lab"
      department: "Immunology"
      grantNumber: "NSF-MCB-2613847"
      sequencingObjective: "Long-read WGS, 100x"
      targetSampleCount: 10
      samplesReceived: 10
      samplesCompleted: 8
      startDate: "2025-11-01"
      targetDate: "2026-02-28"
      active: false
      notes: "Project near completion — final 2 samples in analysis."

  # ── Instruments ────────────────────────────────────────────────

  - action: adl.lims.instrument.create
    as: admin
    data:
      name: "NovaSeq-1"
      platform: novaseq_6000
      model: "NovaSeq 6000"
      serialNumber: "NS6K-A00851"
      status: available
      location: "Sequencing Core, Room 312, Bay A"
      ipAddress: "10.120.5.10"
      softwareVersion: "1.8.1"
      purchaseDate: "2023-06-15"
      warrantyExpires: "2026-06-15"
      lastMaintenanceDate: "2026-02-20"
      nextMaintenanceDate: "2026-05-20"
      totalRuns: 342
      notes: "Primary high-throughput instrument. PM every 90 days. Laser replaced Jan 2025."

  - action: adl.lims.instrument.create
    as: admin
    data:
      name: "NextSeq-1"
      platform: nextseq_2000
      model: "NextSeq 2000"
      serialNumber: "VH01234"
      status: in_use
      location: "Sequencing Core, Room 312, Bay B"
      ipAddress: "10.120.5.11"
      softwareVersion: "1.5.0"
      purchaseDate: "2024-01-20"
      warrantyExpires: "2027-01-20"
      lastMaintenanceDate: "2026-01-15"
      nextMaintenanceDate: "2026-04-15"
      totalRuns: 87
      notes: "Mid-throughput workhorse. Currently running 16S amplicon batch."

  - action: adl.lims.instrument.create
    as: admin
    data:
      name: "MiSeq-Bench3"
      platform: miseq
      model: "MiSeq"
      serialNumber: "MS2-04178"
      status: maintenance
      location: "Sequencing Core, Room 314, Bench 3"
      ipAddress: "10.120.5.15"
      softwareVersion: "4.0.0.1769"
      purchaseDate: "2021-03-10"
      warrantyExpires: "2024-03-10"
      lastMaintenanceDate: "2026-03-10"
      nextMaintenanceDate: "2026-06-10"
      totalRuns: 518
      notes: "Pump assembly replaced March 2026 — PM in progress, ETA back online March 25."

  - action: adl.lims.instrument.create
    as: admin
    data:
      name: "MinION-1"
      platform: minion
      model: "MinION Mk1C"
      serialNumber: "MN38920"
      status: available
      location: "Sequencing Core, Room 314, Bench 1"
      ipAddress: "10.120.5.20"
      softwareVersion: "24.02.5"
      purchaseDate: "2025-02-01"
      warrantyExpires: "2027-02-01"
      lastMaintenanceDate: "2026-02-01"
      nextMaintenanceDate: "2026-08-01"
      totalRuns: 24
      notes: "Long-read nanopore sequencer. Flow cells stored at 4C in cold room."

  # ── Protocols ──────────────────────────────────────────────────

  - action: adl.lims.protocol.create
    as: admin
    data:
      name: "WGS 30x Human"
      version: "3.2"
      category: "Whole Genome"
      description: "Standard whole-genome sequencing protocol at 30x mean coverage for human samples. Nextera DNA Flex library prep with 350bp target insert size. Sequenced on NovaSeq 6000 S4 flow cell, 2x150bp paired-end."
      applicableSampleTypes: ["dna"]
      applicablePlatforms: ["novaseq_6000"]
      recommendedKit: nextera_dna_flex
      inputRequirements: "100-500ng genomic DNA, DIN >= 6, A260/280 1.7-2.0"
      estimatedDuration: "6 hours"
      estimatedTurnaround: "5 business days"
      readConfiguration: "2x150bp PE"
      targetCoverage: "30x"
      active: true
      author: "Dr. Wei Chen"
      approvedDate: "2025-09-01"

  - action: adl.lims.protocol.create
    as: admin
    data:
      name: "RNA-seq polyA mRNA"
      version: "2.1"
      category: "RNA-seq"
      description: "Poly-A selection RNA-seq for differential gene expression analysis. TruSeq Stranded mRNA library prep. Minimum 50M paired-end reads per sample. Sequenced on NovaSeq 6000 or NextSeq 2000."
      applicableSampleTypes: ["rna"]
      applicablePlatforms: ["novaseq_6000", "nextseq_2000"]
      recommendedKit: truseq_stranded_mrna
      inputRequirements: "500ng-1ug total RNA, RIN >= 7"
      estimatedDuration: "8 hours"
      estimatedTurnaround: "7 business days"
      readConfiguration: "2x150bp PE"
      targetCoverage: "50M reads"
      active: true
      author: "Maria Garcia"
      approvedDate: "2025-11-15"

  - action: adl.lims.protocol.create
    as: admin
    data:
      name: "16S V3-V4 Amplicon"
      version: "1.4"
      category: "Amplicon"
      description: "16S rRNA gene V3-V4 region amplicon sequencing for microbiome profiling. Two-step PCR with Illumina adapter ligation. Sequenced on MiSeq 2x300bp or NextSeq 2x250bp."
      applicableSampleTypes: ["dna"]
      applicablePlatforms: ["miseq", "nextseq_2000"]
      recommendedKit: nextera_dna_flex
      inputRequirements: "10-50ng genomic DNA or crude lysate"
      estimatedDuration: "4 hours"
      estimatedTurnaround: "3 business days"
      readConfiguration: "2x300bp PE"
      targetCoverage: "100k reads/sample"
      active: true
      author: "James O'Connor"
      approvedDate: "2025-07-20"

  - action: adl.lims.protocol.create
    as: admin
    data:
      name: "ONT Long-Read WGS"
      version: "1.0"
      category: "Whole Genome"
      description: "Oxford Nanopore long-read whole genome sequencing for de novo assembly and structural variant detection. Ligation sequencing kit with native barcoding. Run on MinION Mk1C or PromethION."
      applicableSampleTypes: ["dna"]
      applicablePlatforms: ["minion"]
      recommendedKit: nanopore_ligation
      inputRequirements: "1ug high-molecular-weight DNA, DIN >= 8, fragment size > 20kb"
      estimatedDuration: "2 hours prep + 48 hours sequencing"
      estimatedTurnaround: "5 business days"
      readConfiguration: "Long-read (N50 > 15kb)"
      targetCoverage: "100x"
      active: true
      author: "James O'Connor"
      approvedDate: "2026-01-10"

  - action: adl.lims.protocol.create
    as: admin
    data:
      name: "Whole Exome Human"
      version: "2.0"
      category: "Exome"
      description: "Whole-exome sequencing using Twist Bioscience Human Core Exome panel. Captures 36Mb of coding regions. Sequenced on NovaSeq 6000 or NextSeq 2000 at 100x mean coverage."
      applicableSampleTypes: ["dna", "ffpe"]
      applicablePlatforms: ["novaseq_6000", "nextseq_2000"]
      recommendedKit: twist_exome
      inputRequirements: "100-200ng genomic DNA, DIN >= 5 (FFPE acceptable)"
      estimatedDuration: "10 hours (includes hybridization)"
      estimatedTurnaround: "7 business days"
      readConfiguration: "2x150bp PE"
      targetCoverage: "100x"
      active: true
      author: "Dr. Wei Chen"
      approvedDate: "2026-02-01"

  # ── Samples ────────────────────────────────────────────────────
  #
  # Samples reference projects by projectId. Since UUIDs are auto-generated,
  # the seeder must resolve project references at runtime. The projectName
  # field is denormalized for display.

  - action: adl.lims.sample.create
    as: maria
    data:
      name: "BRCA-T001"
      externalId: "BIO-2026-0842-T001"
      sampleType: dna
      status: received
      organism: human
      tissue: "Breast tumor, core biopsy"
      preservationMethod: "Fresh frozen"
      collectionDate: "2026-02-20"
      concentration: 42.5
      volume: 30.0
      totalAmount: 1275.0
      a260_280: 1.82
      a260_230: 2.05
      projectName: "BRCA Whole Genome Sequencing"
      projectId: "lookup:project:name:BRCA Whole Genome Sequencing"
      notes: "Tumor sample, matched normal is BRCA-N001."

  - action: adl.lims.sample.create
    as: maria
    data:
      name: "BRCA-N001"
      externalId: "BIO-2026-0842-N001"
      sampleType: dna
      status: received
      organism: human
      tissue: "Peripheral blood, buffy coat"
      preservationMethod: "Fresh frozen"
      collectionDate: "2026-02-20"
      concentration: 58.3
      volume: 25.0
      totalAmount: 1457.5
      a260_280: 1.85
      a260_230: 2.12
      projectName: "BRCA Whole Genome Sequencing"
      projectId: "lookup:project:name:BRCA Whole Genome Sequencing"
      notes: "Matched normal for BRCA-T001."

  - action: adl.lims.sample.create
    as: maria
    data:
      name: "BRCA-T002"
      externalId: "BIO-2026-0842-T002"
      sampleType: dna
      status: received
      organism: human
      tissue: "Breast tumor, surgical resection"
      preservationMethod: "Fresh frozen"
      collectionDate: "2026-02-22"
      concentration: 35.8
      volume: 40.0
      totalAmount: 1432.0
      a260_280: 1.79
      a260_230: 1.95
      projectName: "BRCA Whole Genome Sequencing"
      projectId: "lookup:project:name:BRCA Whole Genome Sequencing"

  - action: adl.lims.sample.create
    as: maria
    data:
      name: "CRC-ORG-D1R1"
      externalId: "PATEL-CRC-D1-REP1"
      sampleType: rna
      status: received
      organism: human
      tissue: "Colorectal organoid, Drug-1 treated"
      preservationMethod: "RNAlater"
      collectionDate: "2026-03-05"
      concentration: 120.0
      volume: 20.0
      totalAmount: 2400.0
      a260_280: 2.01
      a260_230: 2.18
      rin: 9.2
      projectName: "Colorectal Organoid RNA-seq"
      projectId: "lookup:project:name:Colorectal Organoid RNA-seq"
      notes: "Drug-1 (5-FU 10uM), 72hr treatment, biological replicate 1."

  - action: adl.lims.sample.create
    as: maria
    data:
      name: "CRC-ORG-D1R2"
      externalId: "PATEL-CRC-D1-REP2"
      sampleType: rna
      status: received
      organism: human
      tissue: "Colorectal organoid, Drug-1 treated"
      preservationMethod: "RNAlater"
      collectionDate: "2026-03-05"
      concentration: 98.4
      volume: 22.0
      totalAmount: 2164.8
      a260_280: 1.98
      a260_230: 2.10
      rin: 8.8
      projectName: "Colorectal Organoid RNA-seq"
      projectId: "lookup:project:name:Colorectal Organoid RNA-seq"
      notes: "Drug-1 (5-FU 10uM), 72hr treatment, biological replicate 2."

  - action: adl.lims.sample.create
    as: maria
    data:
      name: "MG-16S-D1T1-M01"
      externalId: "PATEL-MG-DIET1-T1-01"
      sampleType: dna
      status: received
      organism: mouse
      tissue: "Cecal contents"
      preservationMethod: "Ethanol-fixed"
      collectionDate: "2026-01-20"
      concentration: 15.2
      volume: 50.0
      totalAmount: 760.0
      a260_280: 1.75
      a260_230: 1.60
      projectName: "Mouse Gut Microbiome 16S"
      projectId: "lookup:project:name:Mouse Gut Microbiome 16S"
      notes: "High-fat diet, timepoint 1 (week 2), mouse 01."

  - action: adl.lims.sample.create
    as: maria
    data:
      name: "ECOLI-WT-001"
      externalId: "PATEL-EC-WT-001"
      sampleType: dna
      status: received
      organism: ecoli
      tissue: "Liquid culture, log phase"
      preservationMethod: "Fresh frozen"
      collectionDate: "2025-11-15"
      concentration: 210.0
      volume: 15.0
      totalAmount: 3150.0
      a260_280: 1.88
      a260_230: 2.15
      din: 9.5
      projectName: "E. coli Genome Assembly"
      projectId: "lookup:project:name:E. coli Genome Assembly"
      notes: "Wild-type K-12 MG1655 reference strain."

  - action: adl.lims.sample.create
    as: maria
    data:
      name: "BRCA-FFPE-001"
      externalId: "PATHOLOGY-2026-1104"
      sampleType: ffpe
      status: received
      organism: human
      tissue: "Breast tumor, FFPE block"
      preservationMethod: "FFPE"
      collectionDate: "2025-12-10"
      concentration: 22.1
      volume: 35.0
      totalAmount: 773.5
      a260_280: 1.72
      a260_230: 1.45
      din: 3.8
      projectName: "BRCA Whole Genome Sequencing"
      projectId: "lookup:project:name:BRCA Whole Genome Sequencing"
      qcNotes: "FFPE sample — moderate fragmentation, DIN 3.8. Recommend exome capture rather than WGS."
      notes: "Archival FFPE block from surgical pathology. May require protocol adjustment."

  # ── Runs ───────────────────────────────────────────────────────
  #
  # Runs reference instruments and protocols by their IDs (auto-generated).
  # Denormalized name fields provided for display.

  - action: adl.lims.run.create
    as: maria
    data:
      name: "NS6K-20260315-WGS-001"
      flowCellId: "HFCM5DRXY"
      flowCellType: "S4"
      status: planned
      instrumentName: "NovaSeq-1"
      instrumentId: "lookup:instrument:name:NovaSeq-1"
      protocolName: "WGS 30x Human"
      protocolId: "lookup:protocol:name:WGS 30x Human"
      operatorId: "maria"
      operatorName: "Maria Garcia"
      readLength: "2x150bp"
      indexReads: "8+8bp"
      loadingConcentration: 300.0
      phiXPercent: 1.0
      scheduledDate: "2026-03-20"
      notes: "BRCA WGS batch 1 — 8 tumor/normal pairs. S4 flow cell for maximum throughput."

  - action: adl.lims.run.create
    as: james
    data:
      name: "NS2K-20260310-RNA-001"
      flowCellId: "VH00234-P25"
      flowCellType: "P2"
      status: planned
      instrumentName: "NextSeq-1"
      instrumentId: "lookup:instrument:name:NextSeq-1"
      protocolName: "RNA-seq polyA mRNA"
      protocolId: "lookup:protocol:name:RNA-seq polyA mRNA"
      operatorId: "james"
      operatorName: "James O'Connor"
      readLength: "2x150bp"
      indexReads: "10+10bp"
      loadingConcentration: 750.0
      phiXPercent: 1.0
      scheduledDate: "2026-03-22"
      notes: "Colorectal organoid RNA-seq — 12 samples pooled (Drug-1 and Drug-2, 3 replicates each)."

  - action: adl.lims.run.create
    as: james
    data:
      name: "MN-20260305-ECOLI-003"
      flowCellId: "FAW92841"
      flowCellType: "R10.4.1"
      status: planned
      instrumentName: "MinION-1"
      instrumentId: "lookup:instrument:name:MinION-1"
      protocolName: "ONT Long-Read WGS"
      protocolId: "lookup:protocol:name:ONT Long-Read WGS"
      operatorId: "james"
      operatorName: "James O'Connor"
      readLength: "Long-read (N50 target >15kb)"
      loadingConcentration: 20.0
      scheduledDate: "2026-03-08"
      notes: "E. coli strain ECOLI-WT-001 and ECOLI-ENG-002. Native barcoding, 48hr run."

  - action: adl.lims.run.create
    as: maria
    data:
      name: "MS-20260325-16S-012"
      flowCellId: "BFCL2DRXY"
      flowCellType: "v3"
      status: planned
      instrumentName: "MiSeq-Bench3"
      instrumentId: "lookup:instrument:name:MiSeq-Bench3"
      protocolName: "16S V3-V4 Amplicon"
      protocolId: "lookup:protocol:name:16S V3-V4 Amplicon"
      operatorId: "maria"
      operatorName: "Maria Garcia"
      readLength: "2x300bp"
      indexReads: "8+8bp"
      loadingConcentration: 6.0
      phiXPercent: 15.0
      scheduledDate: "2026-03-28"
      notes: "Mouse gut microbiome 16S — 48 samples pooled. High PhiX for amplicon diversity."

  # ── Analyses ───────────────────────────────────────────────────
  #
  # Analyses reference runs by runId (auto-generated).
  # Denormalized runName provided for display.

  - action: adl.lims.analysis.create
    as: james
    data:
      name: "WGS-Align-BRCA-Batch1"
      pipeline: "GATK-HaplotypeCaller"
      pipelineVersion: "4.5.0"
      referenceGenome: "GRCh38"
      status: queued
      runName: "NS6K-20260315-WGS-001"
      runId: "lookup:run:name:NS6K-20260315-WGS-001"
      submittedBy: "james"
      submittedByName: "James O'Connor"
      notes: "Alignment and germline variant calling for BRCA WGS batch 1. Output to /data/analysis/brca-wgs-001/"

  - action: adl.lims.analysis.create
    as: james
    data:
      name: "RNAseq-DGE-CRC-Organoid"
      pipeline: "nf-core/rnaseq"
      pipelineVersion: "3.14.0"
      referenceGenome: "GRCh38"
      status: queued
      runName: "NS2K-20260310-RNA-001"
      runId: "lookup:run:name:NS2K-20260310-RNA-001"
      submittedBy: "james"
      submittedByName: "James O'Connor"
      notes: "Differential gene expression analysis for colorectal organoid drug response study."

  - action: adl.lims.analysis.create
    as: james
    data:
      name: "Assembly-ECOLI-WT001"
      pipeline: "Flye"
      pipelineVersion: "2.9.3"
      referenceGenome: "K-12 MG1655"
      status: queued
      runName: "MN-20260305-ECOLI-003"
      runId: "lookup:run:name:MN-20260305-ECOLI-003"
      submittedBy: "james"
      submittedByName: "James O'Connor"
      notes: "De novo genome assembly of wild-type E. coli K-12 strain using Flye long-read assembler."

  - action: adl.lims.analysis.create
    as: maria
    data:
      name: "16S-QIIME2-MG-Batch5"
      pipeline: "QIIME2"
      pipelineVersion: "2024.5"
      referenceGenome: "SILVA 138.1"
      status: queued
      runName: "MS-20260325-16S-012"
      runId: "lookup:run:name:MS-20260325-16S-012"
      submittedBy: "maria"
      submittedByName: "Maria Garcia"
      notes: "16S amplicon analysis with DADA2 denoising and SILVA taxonomy classification. Mouse gut microbiome samples."
