```ts
export function invoiceTotal(lines: { qty: number; unit: number; discount: number }[], rate: number): { subtotal: number; tax: number; total: number } {
  if (lines.length === 0) {
    throw new Error("Lines cannot be empty");
  }

  const validateLine = (line: { qty: number; unit: number; discount: number }) => {
    if (!Number.isInteger(line.qty) || line.qty <= 0) {
      throw new Error("Quantity must be a positive integer");
    }
    if (!Number.isInteger(line.unit) || line.unit < 0) {
      throw new Error("Unit price must be a non-negative integer");
    }
    if (!Number.isInteger(line.discount) || line.discount < 0 || line.discount > 10000) {
      throw new Error("Discount rate must be an integer between 0 and 10000");
    }
  };

  lines.forEach(validateLine);

  const calculateNet = (line: { qty: number; unit: number; discount: number }): number => {
    const gross = line.qty * line.unit;
    const rebate = Math.round((gross * line.discount) / 10000);
    return gross - rebate;
  };

  const subtotal = lines.reduce((acc, line) => acc + calculateNet(line), 0);

  if (!Number.isInteger(rate) || rate < 0 || rate > 10000) {
    throw new Error("Tax rate must be an integer between 0 and 10000");
  }

  const tax = Math.round((subtotal * rate) / 10000);
  const total = subtotal + tax;

  return { subtotal, tax, total };
}
```