// fake data for the pipelines tab until it is wired to bobbin

import type { PipelineSummary } from "$lib/components/repo/types";

const minutes = (n: number) => n * 60_000;

// fixed base so the times do not depend on when this runs
const base = Date.parse("2026-08-04T09:00:00Z");
const ago = (mins: number) => new Date(base - minutes(mins)).toISOString();

export const pipelines: PipelineSummary[] = [
	// a run still in flight
	{
		id: "01K1XJ4WPQ0000000000000001",
		sha: "9f2c1ab4d8e7350f6b1c2d9e4a5b6c7d8e9f0a1b",
		createdAt: ago(3),
		trigger: { kind: "push", targetRef: "master" },
		workflows: [
			{ name: "build", status: "success", duration: minutes(1) + 12_000 },
			{ name: "test", status: "running", duration: 0 },
			{ name: "lint", status: "pending", duration: 0 }
		]
	},
	// mixed outcome
	{
		id: "01K1XJ4WPQ0000000000000002",
		sha: "3d7e91c05fa2b8461d0e5c7a9b3f2e1d4c6a8b0f",
		createdAt: ago(47),
		trigger: {
			kind: "pull_request",
			targetRef: "master",
			sourceLabel: "oppi.li/core:fix-packfile-timeout",
			pullPath: "/tangled.org/core/pulls/42"
		},
		workflows: [
			{ name: "build", status: "success", duration: minutes(2) + 4_000 },
			{ name: "test", status: "failed", duration: minutes(6) + 31_000, error: "3 tests failed" },
			{ name: "lint", status: "success", duration: 41_000 }
		]
	},
	// all green
	{
		id: "01K1XJ4WPQ0000000000000003",
		sha: "c1b4a7e2f9308d65b2a1c4e7f0d3b6a9c2e5f8b1",
		createdAt: ago(190),
		trigger: { kind: "push", targetRef: "master" },
		workflows: [
			{ name: "build", status: "success", duration: minutes(1) + 58_000 },
			{ name: "test", status: "success", duration: minutes(5) + 12_000 },
			{ name: "lint", status: "success", duration: 39_000 }
		]
	},
	// a spindle that never answered
	{
		id: "01K1XJ4WPQ0000000000000004",
		sha: "7a0f3b8c1d2e4f5a6b7c8d9e0f1a2b3c4d5e6f70",
		createdAt: ago(320),
		trigger: { kind: "manual" },
		workflows: []
	},
	// timed out
	{
		id: "01K1XJ4WPQ0000000000000005",
		sha: "e5d4c3b2a1908f7e6d5c4b3a2918f7e6d5c4b3a2",
		createdAt: ago(1_450),
		trigger: {
			kind: "pull_request",
			targetRef: "release-1.4",
			sourceLabel: "bump-deps"
		},
		workflows: [
			{ name: "build", status: "success", duration: minutes(2) + 9_000 },
			{ name: "e2e", status: "timeout", duration: minutes(30) }
		]
	},
	// cancelled mid-run
	{
		id: "01K1XJ4WPQ0000000000000006",
		sha: "b8c7d6e5f4a3b2c1d0e9f8a7b6c5d4e3f2a1b0c9",
		createdAt: ago(2_880),
		// the appview strips refs/heads/ and refs/tags/ before it reaches the card
		trigger: { kind: "push", targetRef: "v1.3.0" },
		workflows: [
			{ name: "build", status: "cancelled", duration: 18_000 },
			{ name: "release", status: "cancelled", duration: 0 }
		]
	}
];
