{ pkgs, lib, config, inputs, ... }:

{
  packages = [
     pkgs.bun
     pkgs.nodejs_24
     pkgs.watchexec
     pkgs.sqlc
     pkgs.dbmate
     pkgs.air
     pkgs.buf
     pkgs.protoc-gen-go
     pkgs.protoc-gen-connect-go
     pkgs.protoc-gen-es
     pkgs.cobra-cli
  ];
  <@if(eq(context.project.mobile,"expo"))>
  android = {
    enable = true;
    emulator = {
      enable = true;
    };
    buildTools.version = ["34.0.0" "35.0.0" "36.0.0" ];  # add 36.0.0
    reactNative.enable = true;
    android-studio = {
      enable = false;
    };
    ndk = {
      enable = true;
      version = [ "27.1.12297006" ];
    };
  };
 <@endif>
  languages.go.enable = true;
  languages.typescript.enable = true;
  services.postgres = {
    enable = true;
    listen_addresses = "127.0.0.1";
    initialDatabases = [
      {
        name = "<@var(context.project.name)>";
        user = "pp";
        pass = "<@var(context.project.name)>";
      }
    ];
  };
  scripts.create-avd.exec = ''
    if [ ! -f .avd-created ]; then
      avdmanager create avd
      -n "Pixel_5_API34"
      -k "system-images;android-34;google_apis_playstore;x86_64"
      -d "pixel_5"
    fi
  '';
  <@endif>
  processes = {
    <@if(neq(context.project.frontend,"none"))>
        bundev = {
          exec = "bun dev";
          cwd = "./apps/web";
          after= ["devenv:processes:air@started"];
        };
    <@endif>
    air = {
      exec = "air";
      cwd = "./services/api";
      after = ["devenv:processes:postgres"];
    };
    protowatcher = {
      exec = "buf generate";
      cwd = "./packages/proto";
      watch = {
        paths = [ ./ ];
        extensions = [ "proto" ];
      };
      after= ["devenv:processes:air@started"];
    };
    protojswatcher = {
      exec = "bun run ./scripts/gen-rpc-index.ts";
      cwd = "./packages/rpc/src";
      watch = {
        paths = [ ./ ];
        extensions = ["js","ts"];
      };
      after= ["devenv:processes:protowatcher@after"];
    };
    <@if(eq(context.project.mobile,"expo"))>
    createavd = {
      exec = "create-avd"
    };
    emulator = {
      exec = "emulator -avd Pixel_5_API34"
      after = ["devenv:processes:createavd@after"]
    };
    bundev = {
      exec = "bunx expo run:android";
      cwd = "./apps/mobile";
      after= ["devenv:processes:emulator@started"];
    };
    <@endif>
    sqlwatcher = {
      exec = "watchexec -w ./db/migrations -w ./db/query -r -e sql sqlc generate";
      cwd = "./services/api";
      after= ["devenv:processes:air@started"];
    };
    
  };
}
